Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def snakepath(path, size):
- x = path[-1]%size
- y = path[-1]//size
- possible = []
- if 0 <= y-1 and path[-1]-size not in path: #up
- possible.append(path[-1]-size)
- if 0 <= x-1 and path[-1]-1 not in path: #left
- possible.append(path[-1]-1)
- if x+1 < size and path[-1]+1 not in path: #right
- possible.append(path[-1]+1)
- if y+1 < size and path[-1]+size not in path: #down
- possible.append(path[-1]+size)
- for direction in possible:
- new = path+(direction,)
- yield new
- for p in snakepath(new, size):
- yield p
- size = 6
- start = 0, 1
- for path in snakepath(start, size):
- if len(path) == size**2 and path[-1] == size:
- print(*path, sep='-')
Advertisement
Add Comment
Please, Sign In to add comment