day 21: more minor prettification for no reason
This commit is contained in:
parent
79ff63e453
commit
318749e6b3
13
21.rkt
13
21.rkt
|
@ -9,21 +9,20 @@
|
||||||
|
|
||||||
(define (part1 input)
|
(define (part1 input)
|
||||||
(match-define (data lines all-is all-as tainted) input)
|
(match-define (data lines all-is all-as tainted) input)
|
||||||
(define untainted (set-subtract all-is (apply set-union (hash-values tainted))))
|
(define all-tainted (apply set-union (hash-values tainted)))
|
||||||
(for*/sum ([l (in-list lines)] [i (in-set (line-is l))] #:when (set-member? untainted i))
|
|
||||||
|
(for*/sum ([l (in-list lines)] [i (in-set (line-is l))] #:unless (set-member? all-tainted i))
|
||||||
1))
|
1))
|
||||||
|
|
||||||
(define (part2 input)
|
(define (part2 input)
|
||||||
(match-define (data lines all-is all-as tainted) input)
|
(match-define (data lines all-is all-as tainted) input)
|
||||||
(define edges
|
(define G (undirected-graph
|
||||||
(for*/list ([(k v*) (in-hash tainted)] [v (in-set v*)])
|
(for*/list ([(k v*) (in-hash tainted)] [v (in-set v*)])
|
||||||
(list k v)))
|
(list k v))))
|
||||||
(define G (undirected-graph edges))
|
|
||||||
(define matching (maximum-bipartite-matching G))
|
(define matching (maximum-bipartite-matching G))
|
||||||
|
|
||||||
(string-join
|
(string-join
|
||||||
(for/list ([val (in-list (sort matching #{string<? (first %1) (first %2)}))])
|
(map second (sort matching string<? #:key first))
|
||||||
(second val))
|
|
||||||
","))
|
","))
|
||||||
|
|
||||||
;; parse input file
|
;; parse input file
|
||||||
|
|
Loading…
Reference in New Issue