What I am trying to do is generate all possible permutations of 1 and 0 given a particular sample size. For instance with a sample of n=8 I would like the m = 2^8 = 256 possible permutations, i.e:
I have been doing this in R, but it is very slow. Is there a quick way to do this in the Julia programming language?
These are just the numbers from 0
to 2^k-1
, written in binary.
# Strings
k=8
[ bin(n,k) for n in 0:2^k-1 ]
# Arrays
[ [ bit == '1' ? 1 : 0 for bit in bin(n,k) ] for n in 0:2^k-1 ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With