-
Notifications
You must be signed in to change notification settings - Fork 1
/
52.ss
38 lines (31 loc) · 916 Bytes
/
52.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
32
33
34
35
36
37
38
#lang racket
(require (except-in srfi/1 first second)
"digits.ss")
(define (all-equal? . things)
(let loop ([things things])
(cond
((null? things)
#t)
((null? (cdr things))
#t)
(else
(if (not (equal? (car things)
(cadr things)))
#f
(loop (cdr things)))))))
(define (same-digits? . numbers)
(apply all-equal? (map (compose (curry apply set) digits) numbers)))
(module+ test
(require (planet schematics/schemeunit:3))
(check-true (same-digits? 12 21))
(check-true (same-digits? 123 321 312))
(check-false (same-digits? 12 22))
(check-false (same-digits? 10 1)))
(define (winner? x)
(apply
same-digits?
(map ((curryr *) x)(build-list 5 (compose add1 add1)))))
(let loop ([candidate 1])
(if (winner? candidate)
(map ((curryr *) candidate) (build-list 6 add1))
(loop (add1 candidate))))