You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
651 B
Racket
22 lines
651 B
Racket
#lang br
|
|
(require racket/file rackunit graph)
|
|
|
|
(define (string->orbits str)
|
|
(for/list ([ln (in-list (string-split str))])
|
|
(map string->symbol (string-split ln ")"))))
|
|
|
|
(define orbit-recs (string->orbits (file->string "06.rktd")))
|
|
|
|
(define (count-orbits orbit-recs)
|
|
(match/values (bfs (undirected-graph orbit-recs) 'COM)
|
|
[(dists _) (apply + (hash-values dists))]))
|
|
|
|
;; 1
|
|
(check-eq? (count-orbits orbit-recs) 261306)
|
|
|
|
(define (count-transfers orbit-recs)
|
|
(match/values (bellman-ford (undirected-graph orbit-recs) 'YOU)
|
|
[(dists _) (- (hash-ref dists 'SAN) 2)]))
|
|
|
|
;; 2
|
|
(check-eq? (count-transfers orbit-recs) 382) |