diff --git a/21.rkt b/21.rkt index e928b8a..3808d54 100644 --- a/21.rkt +++ b/21.rkt @@ -9,21 +9,20 @@ (define (part1 input) (match-define (data lines all-is all-as tainted) input) - (define untainted (set-subtract all-is (apply set-union (hash-values tainted)))) - (for*/sum ([l (in-list lines)] [i (in-set (line-is l))] #:when (set-member? untainted i)) + (define all-tainted (apply set-union (hash-values tainted))) + + (for*/sum ([l (in-list lines)] [i (in-set (line-is l))] #:unless (set-member? all-tainted i)) 1)) (define (part2 input) (match-define (data lines all-is all-as tainted) input) - (define edges - (for*/list ([(k v*) (in-hash tainted)] [v (in-set v*)]) - (list k v))) - (define G (undirected-graph edges)) + (define G (undirected-graph + (for*/list ([(k v*) (in-hash tainted)] [v (in-set v*)]) + (list k v)))) (define matching (maximum-bipartite-matching G)) (string-join - (for/list ([val (in-list (sort matching #{string