Skip to content

Instantly share code, notes, and snippets.

@otf
Created October 18, 2012 15:04
Show Gist options
  • Save otf/3912414 to your computer and use it in GitHub Desktop.
Save otf/3912414 to your computer and use it in GitHub Desktop.
let rec move (x, y) r g n =
if x < 0 || y < 0 || x > g || y > g then n
elif (x,y) = (g, g) then n + 1
else match List.tryFind ((=) (x, y)) r with
| Some _ -> n
| None ->
[(x + 1, y); (x, y + 1); (x - 1, y); (x, y - 1)]
|> List.map (fun xy -> move xy ((x, y)::r) g)
|> List.fold (|>) n
[<EntryPoint>]
let main argv =
let grids = int argv.[0]
printfn "%A" (move (0,0) [] grids 0)
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment