Jump to content

Generating 0-1 arrays/vectors.

- - - - -

  • Please log in to reply
3 replies to this topic

#1
KamilJ

KamilJ

    Newbie

  • Members
  • Pip
  • 1 posts
Hello everyone!

I have a problem - how can I generate all combinations of arrays composed only of ones and zeros (for given length n)?

For example, n=2:

0,0
0,1
1,0
1,1

And for n=3:

0,0,0
1,0,0
0,1,0
1,1,0
0,0,1
1,0,1
0,1,1
1,1,1

(I am trying to do this with Mathematica 8.0)

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Nested loops or recursive functions come to mind.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
A Binary Counter.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
1d array with increment function
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users