Created
March 25, 2016 23:13
-
-
Save monkeygroover/36f206c2f40861affe96 to your computer and use it in GitHub Desktop.
euler12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let factors number = seq { | |
for divisor in 1 .. (float >> sqrt >> int) number do | |
if number % divisor = 0 then | |
yield divisor | |
if number <> 1 then yield number / divisor //special case condition: when number=1 then divisor=(number/divisor), so don't repeat it | |
} | |
let rec triangle n = match n with | |
| 0 -> 0 | |
| 1 -> 1 | |
| n -> n + triangle(n-1) | |
let r = {1..100000} |> Seq.map(triangle) |> Seq.skipWhile(fun tri -> Seq.length(factors(tri)) <= 500) |> Seq.take(1) | |
printfn "%A" (Seq.toList r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment