MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Binary System Problem


Frieder,

Your problem is not well defined since you did not say how many zeros you
want
to include. There are an infinite number of binary numbers with a fixed
number of 1's.

Here is a solution that lets you decide how many zeros to allow.

insertZero[l_List] := Table[Insert[l, 0, {i}], {i, Length[l] + 1}]

numberOfZeros = 2;
listOfOnes={1,1,1,1};

Nest[Flatten[Map[insertZero, #], 1] & , {listOfOnes},  numberOfZeros] //
Union

{{0, 0, 1, 1, 1, 1}, {0, 1, 0, 1, 1, 1}, {0, 1, 1, 0, 1, 1}, {0, 1, 1, 1, 0,
    1}, {0, 1, 1, 1, 1, 0}, {1, 0, 0, 1, 1, 1}, {1, 0, 1, 0, 1, 1}, {1, 0,
1,
    1, 0, 1}, {1, 0, 1, 1, 1, 0}, {1, 1, 0, 0, 1, 1}, {1, 1, 0, 1, 0, 1},
{1,
    1, 0, 1, 1, 0}, {1, 1, 1, 0, 0, 1}, {1, 1, 1, 0, 1, 0}, {1, 1, 1, 1, 0,
    0}}

FromDigits[#, 10] & /@ %

{1111, 10111, 11011, 11101, 11110, 100111, 101011, 101101, 101110, 110011, \
110101, 110110, 111001, 111010, 111100}

Is this what you wanted?
D Piele

==================================================

----- Original Message -----
From: Frieder Schweigert <FSchweigert at airplus.de>
To: mathgroup at smc.vnet.net
Subject: [mg18659] [mg18621] Binary System Problem


> Hi,
>
> does anybody know an algorithm or generating system for
> those binary numbers with a fix amount of '1's,
> for example (four times '1'):
>
>  1111
> 10111
> 11011
> 11101
> 11110



  • Prev by Date: Rudimentary Spell Checker
  • Next by Date: Re: Re: Re: Select in Math.
  • Previous by thread: Binary System Problem
  • Next by thread: Re: Binary System Problem