MathGroup Archive 2006

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

Search the Archive

Re: need to make a special function


Nabeel Butt wrote:
> Dear Users,
>         I need help on making a special type of function which has the
> following properties.
>    f[1]={{0},{1}}
>    f[2]={{0,0},{0,1},{1,0},{1,1}}
>    f[3]={{0,0,0},{0,0,1},{0,1,0},{0,1,1},{1,0,0},{1,0,1},{1,1,0},{1,1,1}}
> .............so on you can see the pattern emerging.
>  I need a very efficient code to perform the above evaluation in some
> optimization problem.
>     Thanks in advance.
>      regards,
>         Nabeel

Hi Nabeel,

Try

f[(n_Integer)?Positive] := Tuples[{0, 1}, n]

For instance, f[4] returns the list

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

HTH,
Jean-Marc


  • Prev by Date: Re: need to make a special function
  • Next by Date: Re: x=2;Composition[f,FindMinimum][x+1,{x,a}]
  • Previous by thread: Re: need to make a special function
  • Next by thread: Re: need to make a special function