Skip to content

Instantly share code, notes, and snippets.

@drx
Created February 7, 2015 04:30
Show Gist options
  • Save drx/33afaa6b8fe077bfac06 to your computer and use it in GitHub Desktop.
Save drx/33afaa6b8fe077bfac06 to your computer and use it in GitHub Desktop.
import networkx as nx
board = [
[6, 3, 5, 6, 5, 3, 6],
[3, 4, 4, 3, 4, 5, 5],
[4, 5, 3, 2, 3, 4, 6],
[5, 4, 3, 0, 4, 3, 3],
[3, 5, 4, 4, 3, 3, 3],
[3, 4, 3, 1, 3, 3, 2],
[2, 2, 3, 5, 1, 3, 5],
]
G = nx.DiGraph()
for x in range(7):
for y in range(7):
G.add_node((x,y))
for x in range(7):
for y in range(7):
jumps = board[y][x]
for dx, dy in ((-1, 0), (1, 0), (0, 1), (0, -1), (-1, -1), (-1, 1), (1, -1), (1, 1)):
x2, y2 = x+jumps*dx, y+jumps*dy
if x2 < 0 or x2 > 6 or y2 < 0 or y2 > 6:
continue
G.add_edge((x, y), (x2, y2))
print list(nx.all_shortest_paths(G, (3, 6), (3, 3)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment