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])]))
|
||||
|
||||
(define (part1 input)
|
||||
(for/sum ([pair (in-list input)]
|
||||
[idx (in-naturals 1)]
|
||||
(for/sum ([pair (in-list input)] [idx (in-naturals 1)]
|
||||
#:when (= -1 (cmp (first pair) (second pair))))
|
||||
idx))
|
||||
|
||||
(define (part2 input)
|
||||
(define all-packets (list* '((2)) '((6)) (apply append input)))
|
||||
(define sorted (sort all-packets #{= -1 (cmp %1 %2)}))
|
||||
(* (add1 (index-of sorted '((2))))
|
||||
(add1 (index-of sorted '((6))))))
|
||||
(define special '(((2)) ((6))))
|
||||
(define sorted (sort (apply append special input) #{= -1 (cmp %1 %2)}))
|
||||
(~>> special (map #{index-of sorted %}) (map add1) (apply *)))
|
||||
|
||||
(define (parse fname)
|
||||
(define (parse-line line)
|
||||
|
|
Loading…
Reference in New Issue