Skip to content

Instantly share code, notes, and snippets.

@rand00
Created November 20, 2018 07:56
Show Gist options
  • Save rand00/523371b0697a39293333a53389c42873 to your computer and use it in GitHub Desktop.
Save rand00/523371b0697a39293333a53389c42873 to your computer and use it in GitHub Desktop.
project euler no. 15
let combinations combine l l' =
CCList.cartesian_product [l; l']
|> CCList.map (fun [p; p'] -> combine p p')
let paths xmax ymax =
let rec aux x y prev_paths =
if x > xmax || y > ymax then []
else if x = xmax && y = ymax then prev_paths
else
let next_paths = List.flatten [
aux (x+1) y [[ `Right ]];
aux x (y+1) [[ `Down ]];
] in
combinations (@) prev_paths next_paths
in
aux 0 0 [[]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment