2015-06-19.scm 635 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env chibi-scheme
  2. ;; Solution for Nines and Zeros
  3. ;; Given an integer n, find the smallest number consisting only of the
  4. ;; digits zero and nine that is divisible by n.
  5. ;; I am using a brute-force algorithm to start with
  6. ;; Example: 23 --> 990909
  7. (import (scheme base)
  8. (scheme write)
  9. (srfi 1))
  10. (define (number->digits n)
  11. (string->list (number->string n)))
  12. (define (only-9-0? n)
  13. (null? (delete #\0 (delete #\9 (number->digits n)))))
  14. (define (find-9-0-multiple n)
  15. (let loop ((i 1))
  16. (if (only-9-0? (* i n))
  17. (* i n)
  18. (loop (+ i 1)))))
  19. (display (find-9-0-multiple 23))
  20. (newline)