-1

I have a Matrix that is consisted out of 80 cells. My objective is to test each of the possible combinations there are where each combination is 8 cells long.

For instance one of the possible combinations is [0, 1, 2, 3, 4, 5, 6, 7]

I was trying to use the following code to print each of these combinations and all I got was a MemoryError:

comb = combinations(range(80), 8)
for i in list(comb):
    print(i)

My purpose is to actually take i (each combination) and set it in my device and verify it is functional. The print(i) was just intended to verify that I am doing it right and to see some of the combinations.

Is there a more memory efficient way to do this kind of task ?

By the way, I am aware that there are 2.898753715E+10 combinations that I am planning to test.

Moshe S.
  • 2,834
  • 3
  • 19
  • 31
  • You are almost right because at the bottom line I am dealing with a list that holds all the combinations. But, my main interest is not the list (array) but scanning, in a certain way, through all the possible combinations. I am not aware of other way to generate all the possible option other then using itertools.combinations() – Moshe S. Jul 15 '18 at 06:36
  • If your system is 32 bit. I donot think this a right way for u to task like this. You can breakdown the lists and set a threshold for each list. They print each list at a time. There is nothing wrong for py to raise such an Error.... – Marcus.Aurelianus Jul 15 '18 at 06:46

1 Answers1

2

You already know that your list can't fit into memory, and you don't seem to need all combinations in-memory anyway, so why not simply remove the call to list()?

for i in comb:
    set_and_test_if_functional(i)

This will still take about a year to run (assuming you can test one combination per millisecond), but won't cause memory problems.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
  • This solution is good enough for me. I agree that storing these options is an overkill. Is there a more efficient way to store them ? – Moshe S. Jul 15 '18 at 07:26