Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let findPaths n =
- let rec path n x y p =
- if x < 1 || x > n || y < 1 || y > n then failwith (sprintf "Invalid position (%d, %d)" x y)
- match (x, y) with
- | (_, _) when x = n && y = n ->
- printfn "Done"
- (x, y)::p
- | (_, _) when x = n && y < n ->
- printfn "At (%d, %d), can only move down" x y
- (x, y)::path n x (y + 1) p
- | (_, _) when x < n && y = n ->
- printfn "At (%d, %d), can only move right" x y
- (x, y)::path n (x + 1) y p
- | (_, _) ->
- printfn "At (%d, %d), can move right or down" x y
- (x, y)::path n (x + 1) y p
- path n 1 1 []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement