A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.
Considering natural numbers of the form, ab, where a, b 100, what is the maximum digital sum?
;digit-split ;pow ;cartesian-product (defn p56 [] (println (apply max (map (fn [[a b]] (apply + (digit-split (pow a b)))) (cartesian-product (range 1 100) (range 1 100)))) ) )
%run_procs %digit_split %pow p56()-> Ans=run_procs(98,fun(I)->[euler,p56,[I+1,2,self(),0]] end, fun(A,{done,B})->lists:max([A,B]) end,0), io:format("~w~n",[Ans]). p56(_,100,Parent,Max)->Parent ! {done,Max}; p56(A,B,Parent,Max)-> S=lists:sum(digit_split(pow(A,B))), p56(A,B+1,Parent,lists:max([S,Max])).
#Enumerable #dig_split def p56 large=0 (1...100).each do |a| (1...100).each do |b| c=dig_split(a**b).sum large=c if c>large end end puts large end