master
Matthew Butterick 7 years ago
parent b2b70dbc48
commit 2b0fdd766b

@ -0,0 +1,28 @@
#lang reader "../aoc-lang.rkt"
(require graph)
(provide (rename-out [#%mb #%module-begin]))
(define-macro (#%mb (STARS) (NUM <-> . NUMS) ...)
#'(#%module-begin
(define g (unweighted-graph/undirected null))
(for-each (curry add-edge! g NUM) (list . NUMS)) ...
(if (eq? 'STARS ')
(programs-in-group g 0)
(number-of-groups g (list NUM ...)))))
(define (programs-in-group g x) (length (group-of g x)))
(define (group-of g x)
(define-values (connects _) (dijkstra g x))
(for/list ([(k v) (in-hash connects)]
#:when (integer? v))
k))
(define (number-of-groups g nums)
(for/fold ([nums-seen null]
[group-count 0]
#:result group-count)
([num (in-list nums)]
#:unless (memv num nums-seen))
(values (append (group-of g num) nums-seen) (add1 group-count))))

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,8 @@
#lang reader "main.rkt" ; 6
0 <-> 2
1 <-> 1
2 <-> 0, 3, 4
3 <-> 2, 4
4 <-> 2, 3, 6
5 <-> 6
6 <-> 4, 5

@ -0,0 +1,8 @@
#lang reader "main.rkt" ★★ ; 2
0 <-> 2
1 <-> 1
2 <-> 0, 3, 4
3 <-> 2, 4
4 <-> 2, 3, 6
5 <-> 6
6 <-> 4, 5