15,172,004 members
See more: , +
I am new to python coding but would like to use it to generate all the permutations and combinations of a slot car track layout given a list of pieces of track. I figure each piece of track is a block that connects at each end. Curved pieces are just curved blocks. The blocks have to line up one after another in line and make a loop, if it does not make a loop then the layout is discarded. I got as high as 10 pieces of track before I ran out of memory. I have 75 pieces of track made up of straight and curved pieces. This does not take into account each curved piece of track can face up or down.

Lastly I want to save each completed loop layout so I can use it as an input data list to generate a graphical picture of the slot car track layout.

Any help on how to code this would be deeply appreciated.

What I have tried:

import itertools
from pprint import pprint
import numpy as np

#inputdata = [[9,0],[10,45],[10,45],[9,0],[10,45],[10,45]]
#inputdata = [9,9,9,9,9,9,9,9,9,9,9,9,9,9,15,15,15,15,15,15,15,15,15,15,15,6,6,6,6,6,6,6]
inputdata = [9,9,9,15,15,15,15,6,9,3]
result = list(itertools.permutations(inputdata))
outputArrays = np.array_split(result,len(result))
#print(outputArrays[100]) #to print a single list element.
pprint(outputArrays)
Posted
Updated 9-Sep-20 12:59pm
Richard MacCutchan 9-Sep-19 11:26am

Check the itertools documentation to see if it has any limits on the number of values that you can use.

## Solution 1

I have just tried your code and it seems that the duplicate numbers are the cause of the problem.

The problem is the number of elements in your date. The number of permutations of a set is !n. So in your case with 10 elements the number of permutations is !10 or 3,628,800. This is what leads to memory overflow.
v2