day 13 yak shaving
This commit is contained in:
parent
27a857f890
commit
0ccfea0b28
10
13.rkt
10
13.rkt
|
@ -27,16 +27,14 @@
|
||||||
[x x])]))
|
[x x])]))
|
||||||
|
|
||||||
(define (part1 input)
|
(define (part1 input)
|
||||||
(for/sum ([pair (in-list input)]
|
(for/sum ([pair (in-list input)] [idx (in-naturals 1)]
|
||||||
[idx (in-naturals 1)]
|
|
||||||
#:when (= -1 (cmp (first pair) (second pair))))
|
#:when (= -1 (cmp (first pair) (second pair))))
|
||||||
idx))
|
idx))
|
||||||
|
|
||||||
(define (part2 input)
|
(define (part2 input)
|
||||||
(define all-packets (list* '((2)) '((6)) (apply append input)))
|
(define special '(((2)) ((6))))
|
||||||
(define sorted (sort all-packets #{= -1 (cmp %1 %2)}))
|
(define sorted (sort (apply append special input) #{= -1 (cmp %1 %2)}))
|
||||||
(* (add1 (index-of sorted '((2))))
|
(~>> special (map #{index-of sorted %}) (map add1) (apply *)))
|
||||||
(add1 (index-of sorted '((6))))))
|
|
||||||
|
|
||||||
(define (parse fname)
|
(define (parse fname)
|
||||||
(define (parse-line line)
|
(define (parse-line line)
|
||||||
|
|
Loading…
Reference in New Issue