Created
January 17, 2015 00:43
-
-
Save kbourgoin/36af24614f5f5856ffe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"1": [9, 11, 12], | |
"2": [6, 14, 12, 9, 5, 1], | |
"3": [1, 6, 8, 20, 22], | |
"4": [24, 20, 3, 11], | |
"5": [2, 1, 6], | |
"6": [2, 18, 17], | |
"7": [24, 1, 10, 12, 2], | |
"8": [3, 14, 6, 1], | |
"9": [3, 21, 10, 2, 18, 1], | |
"10": [16, 18, 6, 9], | |
"11": [24, 17, 21, 4], | |
"12": [5, 23, 17, 19], | |
"13": [20, 1, 22, 14], | |
"14": [10, 15, 7, 8], | |
"15": [1, 18, 19, 12], | |
"16": [1, 6, 5, 10, 2], | |
"17": [19, 1, 3], | |
"18": [20, 1, 19, 6], | |
"19": [21, 2, 15, 12, 6], | |
"20": [1, 21, 15, 23], | |
"21": [19, 20, 3, 14, 22], | |
"22": [15, 21, 6, 2, 20, 13, 14], | |
"23": [10, 19, 1, 12, 22, 6], | |
"24": [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
data = json.loads(open('./data.json').read()) | |
data = {int(k): v for k,v in data.iteritems()} | |
def nxt(path): | |
here = path[-1] | |
valid = (i for i in data[here] if i not in path) | |
for dest in valid: | |
potential = path + [dest] | |
for v in nxt(potential): | |
yield v | |
else: | |
yield tuple(path) | |
found = set() | |
for path in nxt([1,]): | |
if path in found: | |
continue | |
if path[-1] == 24: | |
print '{:3}: {}'.format(len(path), path) | |
if len(path) == 24: | |
break | |
found.add(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment