day 13 yak shaving

This commit is contained in:
xenia 2022-12-31 16:49:07 -05:00
parent 27a857f890
commit 0ccfea0b28
1 changed files with 4 additions and 6 deletions

10
13.rkt
View File

@ -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)