Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- uncover = {
- 0 : [(1,2),(3,6),(4,8)],
- 1 : [(4,7)],
- 2 : [(1,0),(4,6),(5,8)],
- 3 : [(4,5)],
- 4 : [],
- 5 : [(4,3)],
- 6 : [(3,0),(4,2),(7,8)],
- 7 : [(4,1)],
- 8 : [(7,6),(4,0),(5,2)],
- }
- allpos = range(9)
- cover = lambda c: [x for x in allpos if x not in c]
- available = {
- 0 : cover([0,2,6,8]),
- 1 : cover([1,7]),
- 2 : cover([0,2,6,8]),
- 3 : cover([3,5]),
- 4 : cover([4]),
- 5 : cover([5,3]),
- 6 : cover([0,2,6,8]),
- 7 : cover([7,1]),
- 8 : cover([0,2,6,8]),
- }
- def visible(path):
- last = path[-1]
- vis = list(available[last])
- for c,u in uncover[last]:
- if c in path[:-1]:
- vis.append(u)
- return vis
- def nextpaths(path):
- return [path + [s] for s in visible(path) if s not in path]
- def extend(paths, length):
- if length != 0:
- return extend([np for p in paths for np in nextpaths(p)], length-1)
- else:
- return paths
- corner = [[0]]
- side = [[1]]
- middle = [[4]]
- for length in range(1,9):
- print length, ( 4*len(extend(corner, length))
- + 4*len(extend(side, length))
- + len(extend(middle, length)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement