Skip to content

Instantly share code, notes, and snippets.

@ayato-p
Created July 20, 2013 02:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayato-p/6043545 to your computer and use it in GitHub Desktop.
Save ayato-p/6043545 to your computer and use it in GitHub Desktop.
(define (doctor-away-numbers? a b c)
(let ((b1 (div b 10))
(b2 (mod b 10))
(c1 (div c 10))
(c2 (mod c 10)))
(and (= (+ (* (div b2 a) 10)
(/ (+ (* b1 10) (div b2 a)) a))
c)
(= (apply +
(append
(make-list c1 a)
(make-list c2 a)))
b)
(= (+ (* c1 a) (* c2 a))
b))))
(let loop ((a 1) (b 10) (c 10) (ans '()))
(cond [(= a 10) ans]
[(= b 100) (loop (+ a 1) 10 10 ans)]
[(= c 100) (loop a (+ b 1) 10 ans)]
[else (loop a b (+ c 1) (if (doctor-away-numbers? a b c)
(cons `(,a ,b ,c) ans)
ans))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment