How do I compute all possibilities for an array of numbers/bits (in python, or any language for that matter)

In Python, use itertools for stuff like this

from itertools import product
for i in product([0,1], repeat=5): 
    print i

Yields:

(0, 0, 0, 0, 0)
(0, 0, 0, 0, 1)
(0, 0, 0, 1, 0)
(0, 0, 0, 1, 1)
(0, 0, 1, 0, 0)
etc...

Leave a Comment