Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. let findPaths n =
  2. let rec path n x y p =
  3. if x < 1 || x > n || y < 1 || y > n then failwith (sprintf "Invalid position (%d, %d)" x y)
  4. match (x, y) with
  5. | (_, _) when x = n && y = n ->
  6. printfn "Done"
  7. (x, y)::p
  8. | (_, _) when x = n && y < n ->
  9. printfn "At (%d, %d), can only move down" x y
  10. (x, y)::path n x (y + 1) p
  11. | (_, _) when x < n && y = n ->
  12. printfn "At (%d, %d), can only move right" x y
  13. (x, y)::path n (x + 1) y p
  14. | (_, _) ->
  15. printfn "At (%d, %d), can move right or down" x y
  16. (x, y)::path n (x + 1) y p
  17. path n 1 1 []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement