Problem #30

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44

As 1 = 14 is not a sum it is not included.

The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

Erlang: Running time = 1.56s
```+%run_procs

+%digit_split

+%pow

p30()->
Pows=list_to_tuple(lists:map(fun(X)->pow(X,5) end,lists:seq(0,9))),
Limit=6*pow(9,5),
Ans=run_procs(Limit div 1000,fun(I)->[euler,p30,[check,1000*I,1000*(I+1),0,Pows,self()]] end,
fun(A,{done,B})->A+B end,0),
io:format("~w~n",[Ans]).
p30(check,On,On,Total,_,Parent)->Parent!{done,Total};
p30(check,On,Upto,Total,Pows,Parent)->
Test=lists:sum(lists:map(fun(X)->element(X+1,Pows) end, digit_split(On))),
if
Test==On->
p30(check,On+1,Upto,Total+On,Pows,Parent);
true->
p30(check,On+1,Upto,Total,Pows,Parent)
end.

```
Ruby: Running time = 6.82s
```+#Enumerable

def p30test(n)
n==n.to_s.split("").map{|i|\$fifths[i]}.sum
end

def p30
\$fifths={}
(0..9).each{|i|\$fifths[i.to_s]=i**5}
puts (2..(6*(9**5))).select{|i|p30test i}.sum
end

```