056 Powerful digit sum.sf 440 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # Considering natural numbers of the form, a^b, where a, b < 100, what is the maximum digital sum?
  6. # https://projecteuler.net/problem=56
  7. # Runtime: 0.153s
  8. var max = 0
  9. var r = range(90, 99)
  10. r.each { |i|
  11. r.each { |j|
  12. var sum = (i**j -> sumdigits)
  13. if (sum > max) {
  14. max = sum
  15. }
  16. }
  17. }
  18. say max