# Project Euler Problem 30

Project Euler Problem 30 is about one of these cute number artifacts. It can be noticed that as numbers grow there is a limit to number of digits representable as sum of fifth powers of digits. Max number representable for given number of digits **nd** is **nd*(9**5)**.

As soon as the upper limit is known the rest is straightforward: for each number between 10 (lowest number for which sum of digits is defined) and the upper limit check if it is equal to sum of its fifth powers of digits; if affirmative, add it to the answer:

let maxAsSumOfDigitsPow5 = let ninePow5 = 9*9*9*9*9 let rec maxN (n: int) = if pown 10 n > ninePow5 * n then ninePow5 * n else maxN (n + 1) maxN 2 let asSumOfDigitsPow5 (n: int) = Seq.unfold (fun x -> if x = 0 then None else Some(pown (x%10) 5, x/10) ) n |> Seq.sum let problem030 () = {10..maxAsSumOfDigitsPow5} |> Seq.filter (fun x -> x = asSumOfDigitsPow5 x) |> Seq.sum

Advertisements

Leave a Comment