p063.scm 721 B

12345678910111213141516171819202122232425262728
  1. ;; Powerful digit counts
  2. (define-module (solved p063))
  3. (define (get-n-digit-n-powers)
  4. (define (power-loop power acc)
  5. (if (< 10000 power) ; Just using this arbitrary limit...
  6. acc
  7. (base-loop power 1 acc)))
  8. (define (base-loop power base acc)
  9. (let ([power-length (string-length (number->string (expt base power)))])
  10. (if (> power-length power)
  11. (power-loop (1+ power) acc)
  12. (base-loop power (1+ base)
  13. (if (= power-length power) (1+ acc) acc)))))
  14. (power-loop 1 0))
  15. (define (n-digit-n-power? number)
  16. (let ([n (string-length (number->string number))])
  17. (let loop ([i 1])
  18. (let ([power (expt i n)])
  19. (cond
  20. [(> power number) #f]
  21. [(= power number) #t]
  22. [else (loop (1+ i))])))))