Fix library; use threading in Day 7.

This commit is contained in:
Jonathan Chan 2020-12-07 00:45:50 -08:00
parent 19e87e9dfc
commit 0dbe56a244
3 changed files with 10 additions and 13 deletions

View File

@ -1,7 +1,6 @@
#lang racket
(require
curly-fn
threading
(only-in data/queue
make-queue
@ -10,8 +9,7 @@
read-lines
read-file))
(provide (all-from-out curly-fn
threading)
(provide (all-from-out threading)
problem-input
problem-input-all

View File

@ -20,19 +20,18 @@
(add-vertex! contains outer)]))))
(values contained contains)))
(define (count-bags graph source multiplier)
(define (count-bags graph source)
(let ([neighbours (get-neighbours graph source)])
(* (apply + 1 (map (λ (neighbour)
(let ([weight (edge-weight graph source neighbour)])
(count-bags graph neighbour weight)))
neighbours))
multiplier)))
(apply + 1 (map (λ (neighbour)
(let ([weight (edge-weight graph source neighbour)])
(* weight (count-bags graph neighbour))))
neighbours))))
(define-values (part1 part2)
(let*-values ([(contained contains) (strings->graphs input)]
[(bfs-shiny-gold pred) (bfs contained "shiny gold")]
[(reachables) (count (( != +inf.0) cdr) (hash->list bfs-shiny-gold))]
[(total-bags) (count-bags contains "shiny gold" 1)])
[(reachables) (count (λ~> cdr (!= +inf.0)) (hash->list bfs-shiny-gold))]
[(total-bags) (count-bags contains "shiny gold")])
(values (sub1 reachables) (sub1 total-bags))))
(show-solution part1 part2)

View File

@ -1,6 +1,6 @@
#lang racket
#lang curly-fn racket
(require "../lib.rkt")
(require "lib.rkt")
(define (parse in) in)