master
Matthew Butterick 7 years ago
parent a2d11e5688
commit d11b94c403

@ -0,0 +1,43 @@
#lang br/quicklang
(require "../helper.rkt")
(provide read-syntax (rename-out [#%mb #%module-begin]) ★★)
(define (read-syntax path port)
(define lines (port->lines port))
(strip-context #`(module mod "main.rkt"
#,@(for/list ([datum (in-port read (open-input-string (car lines)))])
datum)
#,@(map (λ (ln) (apply cons (map string->number (string-split ln "/")))) (cdr lines)))))
(define-macro (#%mb STARS DOMS ...)
#'(#%module-begin
(time (STARS '(DOMS ...)))))
(define (find-dominoes-with-val dominoes val)
(filter (λ (d) (or (= (car d) val) (= (cdr d) val))) dominoes))
(define (other-val-on-domino dom val)
((if (= (car dom) val) cdr car) dom))
(define (remove-dom doms dom)
(filter-not (λ (d) (equal? d dom)) doms))
(define (bridges dominoes [current-val 0] [current-bridge null])
(define doms (find-dominoes-with-val dominoes current-val))
(if (null? doms)
(list (flatten current-bridge))
(append-map (λ (dom) (bridges (remove-dom dominoes dom)
(other-val-on-domino dom current-val)
(cons dom current-bridge))) doms)))
(define (strongest bridges)
(apply max (map (λ (br) (apply + br)) bridges)))
(define ( dominoes)
(strongest (bridges dominoes)))
(define (★★ dominoes)
(define brs (bridges dominoes))
(define maxlen (apply max (map length brs)))
(strongest (filter (λ (b) (= maxlen (length b))) brs)))

@ -0,0 +1,58 @@
#lang reader "main.rkt" ; 1868
25/13
4/43
42/42
39/40
17/18
30/7
12/12
32/28
9/28
1/1
16/7
47/43
34/16
39/36
6/4
3/2
10/49
46/50
18/25
2/23
3/21
5/24
46/26
50/19
26/41
1/50
47/41
39/50
12/14
11/19
28/2
38/47
5/5
38/34
39/39
17/34
42/16
32/23
13/21
28/6
6/20
1/30
44/21
11/28
14/17
33/33
17/43
31/13
11/21
31/39
0/9
13/50
10/14
16/10
3/24
7/0
50/50

@ -0,0 +1,58 @@
#lang reader "main.rkt" ★★ ; 1841
25/13
4/43
42/42
39/40
17/18
30/7
12/12
32/28
9/28
1/1
16/7
47/43
34/16
39/36
6/4
3/2
10/49
46/50
18/25
2/23
3/21
5/24
46/26
50/19
26/41
1/50
47/41
39/50
12/14
11/19
28/2
38/47
5/5
38/34
39/39
17/34
42/16
32/23
13/21
28/6
6/20
1/30
44/21
11/28
14/17
33/33
17/43
31/13
11/21
31/39
0/9
13/50
10/14
16/10
3/24
7/0
50/50

@ -0,0 +1,9 @@
#lang reader "main.rkt" ; 31
0/2
2/2
2/3
3/4
3/5
0/1
10/1
9/10

@ -0,0 +1,9 @@
#lang reader "main.rkt" ★★ ; 19
0/2
2/2
2/3
3/4
3/5
0/1
10/1
9/10