Skip to content

Instantly share code, notes, and snippets.

@davidgrenier
Created August 19, 2011 15:09
Show Gist options
  • Save davidgrenier/1157008 to your computer and use it in GitHub Desktop.
Save davidgrenier/1157008 to your computer and use it in GitHub Desktop.
Project Euler 3
let getLPF num =
let rec getLPF l rest =
seq { yield 2L; yield! seq {3L..2L..(rest |> float |> sqrt |> int64)}}
|> Seq.tryFind (fun d -> rest % d = 0L)
|> function
| None -> max l rest
| Some d -> getLPF (max l d) (rest / d)
getLPF 1L num;;
getLPF 600851475143L
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment