Project Euler Problem 56 Solution

Question

A googol ($10^{100}$) is a massive number: one followed by one-hundred zeros; $100^{100}$ 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?

digits :: Integer -> [Integer]
main = print $maximum [sum$ digits $a^b | a <- [1..99], b <- [1..99]] $ ghc -O2 -o digit-sum digit-sum.hs
$time ./digit-sum real 0m0.073s user 0m0.072s sys 0m0.000s Python #!/usr/bin/env python from itertools import * def get_digits(n): return [int(digit) for digit in str(n)] def main(): largest = 0 for a, b in product(list(range(1, 100)), list(range(1, 100))): s = sum(get_digits(a ** b)) if s > largest: largest = s print(largest) if __name__ == "__main__": main() $ time python3 digital-sum.py
sys    0m0.004s