Share via


Project Euler Problem #12

First triangle number to have over five hundred divisors.

let naturals = Seq.unfold (fun i -> Some(i, i + 1)) 1 // from prob7
let triangleNums = Seq.scan (+) 0 naturals
let isFactor n d = n % d = 0
let factors n = seq { 1..int (sqrt (float n)) } |> Seq.filter (isFactor n)
let numFactors n = factors n |> Seq.length
triangleNums |> Seq.find (fun n -> numFactors n > 500 / 2)