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

前端 未结 4 1644
野趣味
野趣味 2020-12-04 01:53

I have been wracking my brains out for 3 hours straight, but I still don\'t get it, so I am asking here. (I wrote Python in the title, but this could be for pretty much any

4条回答
  •  借酒劲吻你
    2020-12-04 02:07

    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...
    

提交回复
热议问题