master
Matthew Butterick 7 years ago
parent 2b0fdd766b
commit 379cd904b5

@ -0,0 +1,25 @@
#lang reader "../aoc-lang.rkt"
(require (for-syntax racket/string racket/sequence) racket/dict)
(provide (rename-out [#%mb #%module-begin]) ★★)
(define-macro (#%mb (STARS) (DEPTH: RANGE) ...)
(with-pattern ([(DEPTH ...)
(for/list ([id (in-syntax #'(DEPTH: ...))])
(string->number (string-trim (symbol->string (syntax->datum id)) ":")))])
#'(#%module-begin (STARS '(DEPTH ...) '(RANGE ...)))))
(define (caught? depth range [delay 0])
(zero? (modulo (+ depth delay) (* 2 (sub1 range)))))
(define ( ds rs)
(for/sum ([d (in-list ds)]
[r (in-list rs)]
#:when (caught? d r))
(* d r)))
(define (★★ ds rs)
(for/first ([delay (in-naturals)]
#:unless (for/or ([d (in-list ds)]
[r (in-list rs)])
(caught? d r delay)))
delay))

@ -0,0 +1,44 @@
#lang reader "main.rkt" ; 1612
0: 3
1: 2
2: 4
4: 6
6: 4
8: 6
10: 5
12: 6
14: 8
16: 8
18: 8
20: 6
22: 12
24: 8
26: 8
28: 10
30: 9
32: 12
34: 8
36: 12
38: 12
40: 12
42: 14
44: 14
46: 12
48: 12
50: 12
52: 12
54: 14
56: 12
58: 14
60: 14
62: 14
64: 14
70: 10
72: 14
74: 14
76: 14
78: 14
82: 14
86: 17
88: 18
96: 26

@ -0,0 +1,44 @@
#lang reader "main.rkt" ★★ ; 3907994
0: 3
1: 2
2: 4
4: 6
6: 4
8: 6
10: 5
12: 6
14: 8
16: 8
18: 8
20: 6
22: 12
24: 8
26: 8
28: 10
30: 9
32: 12
34: 8
36: 12
38: 12
40: 12
42: 14
44: 14
46: 12
48: 12
50: 12
52: 12
54: 14
56: 12
58: 14
60: 14
62: 14
64: 14
70: 10
72: 14
74: 14
76: 14
78: 14
82: 14
86: 17
88: 18
96: 26

@ -0,0 +1,5 @@
#lang reader "main.rkt" ; 24
0: 3
1: 2
4: 4
6: 4

@ -0,0 +1,5 @@
#lang reader "main.rkt" ★★
0: 3
1: 2
4: 4
6: 4