From 0dbe56a244a416824a25415d8de95e6fb7575763 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Mon, 7 Dec 2020 00:45:50 -0800 Subject: [PATCH] Fix library; use threading in Day 7. --- lib.rkt | 4 +--- src/07.rkt | 15 +++++++-------- template.rkt | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib.rkt b/lib.rkt index 99cac7b..af1bd86 100644 --- a/lib.rkt +++ b/lib.rkt @@ -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 diff --git a/src/07.rkt b/src/07.rkt index 2d59131..5bd5703 100644 --- a/src/07.rkt +++ b/src/07.rkt @@ -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) diff --git a/template.rkt b/template.rkt index b690640..30c6750 100644 --- a/template.rkt +++ b/template.rkt @@ -1,6 +1,6 @@ -#lang racket +#lang curly-fn racket -(require "../lib.rkt") +(require "lib.rkt") (define (parse in) in)