From 0ccfea0b282b107e5cf232a3299a07628f8b4c95 Mon Sep 17 00:00:00 2001 From: xenia Date: Sat, 31 Dec 2022 16:49:07 -0500 Subject: [PATCH] day 13 yak shaving --- 13.rkt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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)