Skip to content

Instantly share code, notes, and snippets.

@DeastinY
Created September 23, 2016 09:13
Show Gist options
  • Save DeastinY/7d605d692ce8cb26e12c5dfcbbedca92 to your computer and use it in GitHub Desktop.
Save DeastinY/7d605d692ce8cb26e12c5dfcbbedca92 to your computer and use it in GitHub Desktop.
TOH State Generation
def unique(iterable):
# http://stackoverflow.com/questions/6534430/why-does-pythons-itertools-permutations-contain-duplicates-when-the-original
seen = set()
for i in iterable:
if str(i) in seen:
continue
seen.add(str(i))
yield i
states = [i for i in unique(itertools.permutations([[2,1],[],[]]))] + \
[i for i in unique(itertools.permutations([[2],[1],[]]))] + \
[i for i in unique(itertools.permutations([[1,2],[],[]]))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment