p056.scm 479 B

1234567891011121314151617181920
  1. ;; Powerful digit sum
  2. (define-module (solved p056))
  3. (use-modules (srfi srfi-1)
  4. (euler utils))
  5. (define (find-max-digital-sum limit)
  6. (reduce max 0
  7. (map (lambda (n)
  8. (reduce + 0 (number->digits n)))
  9. (get-expt-nums limit))))
  10. (define (get-expt-nums limit)
  11. (let generator ([a 1] [b 1] [expt-nums '()])
  12. (cond
  13. [(>= a limit) expt-nums]
  14. [(>= b limit) (generator (1+ a) 1 expt-nums)]
  15. [else (generator a (1+ b) (cons (expt a b) expt-nums))])))