-
Notifications
You must be signed in to change notification settings - Fork 1
/
33.ss
32 lines (28 loc) · 1.05 KB
/
33.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#lang scheme
(require (only-in srfi/1 lset-intersection lset-difference)
math/number-theory
"digits.ss")
(apply
*
(for*/fold ([fracs '()])
([bot (in-range 10 100)]
[top (in-range 10 bot)])
(if (zero? (remainder bot 10))
fracs
(let* ((top-digits (digits top))
(bot-digits (digits bot))
(common-digits (lset-intersection equal? top-digits bot-digits)))
(if (not (null? common-digits))
(let ((TOP (digits->number (lset-difference equal? top-digits common-digits)))
(BOT (digits->number (lset-difference equal? bot-digits common-digits))))
(if (or (zero? BOT)
(zero? TOP)
(not (= (/ top bot)
(/ TOP BOT))))
fracs
(begin
(printf "~a / ~a~%" top bot)
(cons
(/ top bot)
fracs))))
fracs)))))