diff --git a/13.rkt b/13.rkt index ab1671e..076c1cc 100644 --- a/13.rkt +++ b/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)