From 98db7e9dcef3b08c0b1a4d32a1e9199ca5225d45 Mon Sep 17 00:00:00 2001 From: haskal Date: Mon, 21 Dec 2020 13:29:20 -0500 Subject: [PATCH] fix issue with maximum-bipartite-matching/stable --- scripts/aoc.rkt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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)))