I have a list[5][5] to populate… it looks like a table with 5 columns and 5 rows.
Each cell can be either one or zero.
I want to find different 2^25 possibility that can exist. Each possiblity is a combination of either 0 or 1 in a 5*5 table/list
How can I do that? With nested loop or something?
I suggest you start small… with a 1×1
listfirst and check that you can display both of the available combinations:Next up, try a 2×2
list. There are 16 differentlists to display:If you’ve got the algorithm right for 1×1 and 2×2, then you should be able to generalise it to print your 5×5.
Good luck!
Update
Since you appear to be still struggling, here’s a little extra help.
Break this problem into smaller problems. I’d start with generating the values. If you ignore the
listnotation in my examples above, you’ll see that the sequence of values is one that is recognisable to every computer scientist on the planet. It’s also pretty easy to generate in Python usingbin()andstr.zfill().The second problem is putting them into
lists. This isn’t too hard either. Supposing the first value in your sequence is ‘0000’. You know that yourlists are two rows by two columns. You can put the first two characters into a list and put that list into a list. Then put the next two characters into a list and append that list to the previous one. Done. Repeat for each value in the sequence.Hope this helps.