Wow, interesting - tough! And I finally found Seq.choose (I was looking for Seq.pickAll).

let problem38a = let isPosPd (nstr:string) = //we know our chars are digits let len = nstr |> Seq.length len = 9 && (nstr.Contains("0") |> not) && len = (nstr |> Seq.distinct |> Seq.length) let tryFind n = let rec loop i = let prodConcats = (seq {for j in 1..i -> n*j |> string }) |> Seq.fold (+) "" if isPosPd prodConcats then Some(prodConcats |> int) elif i < 9 then loop (i+1) else None loop 2 //start with 2 since n > 1 {1..9999} //since n > 1, 9999 is clearly an upper limit |> PSeq.choose tryFind |> PSeq.max

## No comments:

## Post a Comment