diff --git a/scripts/aoc.rkt b/scripts/aoc.rkt index 96040c4..5b98d97 100644 --- a/scripts/aoc.rkt +++ b/scripts/aoc.rkt @@ -44,7 +44,9 @@ (define num-first-lefts (for/sum ([m (in-list matching)] #:when (set-member? left (first m))) 1)) - (if (> num-first-lefts (/ (set-count left) 2)) + ;; if the first set contains more elements belonging to lefts than rights, then assume it's in + ;; the right order. otherwise, swap + (if (> num-first-lefts (- (length matching) num-first-lefts)) matching (map #{list (second %) (first %)} matching)))