055.scm 483 B

123456789101112131415161718192021
  1. ;; Lychrel numbers
  2. (use-modules (euler utils))
  3. (define (number-of-lychrel-numbers-under-n n)
  4. (let loop ((i 0) (acc 0))
  5. (if (>= i n) acc
  6. (loop (1+ i)
  7. (if (lychrel? i) (1+ acc) acc)))))
  8. (define (lychrel? n)
  9. (let loop ((i 2) (curr-n (+ n (number-reverse n))))
  10. (cond
  11. ((>= i 50) #t)
  12. ((palendromic? (number->string curr-n)) #f)
  13. (else (loop (1+ i) (+ curr-n (number-reverse curr-n)))))))
  14. (display (number-of-lychrel-numbers-under-n 10000))
  15. (newline)