Skip to content

Instantly share code, notes, and snippets.

@llasram
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llasram/058e5f43074c2390ac4a to your computer and use it in GitHub Desktop.
Save llasram/058e5f43074c2390ac4a to your computer and use it in GitHub Desktop.
J implementation of Dijkstra's algorithm on a square grid (Project Euler #83)
mask =: _~:]
moves =: 1 :'(0 1, 0 _1, 1 0,: _1 0) |.!.m"1 2 ]'
step =: [:<./ ], (* +./@:(0 moves)@:mask) +"2 (_ moves)@:]
init =: * $ $!._ 1:
costs =: step^:_ init
M =: ([:".(;._1)',',])(;._1)_1|.(1!:1)<'p083_matrix.txt'
] p83 =: {:{: costs M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment