Again, easy problem using functional composition, the “hard” work was done in our previous implementation of the Digits module. The answer was produced surprisingly fast. I would like a better solution to finding the last 10 digits than to convert the entire sequence to an array.
let problem48a = let digits = {1..1000} |> Seq.sumBy (fun n -> BigInteger.Pow(BigInteger(n), n)) |> Digits.fromBigInt |> Seq.toArray Array.sub digits (digits.Length - 10) 10 |> Digits.toInt64 //just makes it easier to copy and paste result
No comments:
Post a Comment