diff options
author | Hunky Jimpjorps <thechairman@thechairman.info> | 2022-11-29 13:09:46 -0500 |
---|---|---|
committer | Hunky Jimpjorps <thechairman@thechairman.info> | 2022-11-29 13:09:46 -0500 |
commit | f803bbca50f6b9faa4107a57b86c66383d253ec2 (patch) | |
tree | 2bca81ff6aa2ad5c79f3f96b40dd1d42cbf52560 /2020/day-07 | |
parent | c871d9cbe4cc6d3063665a428de4b205cef29041 (diff) | |
download | gleam_aoc-f803bbca50f6b9faa4107a57b86c66383d253ec2.tar.gz gleam_aoc-f803bbca50f6b9faa4107a57b86c66383d253ec2.zip |
day 7 tweaking, part 1 of day 8
Diffstat (limited to '2020/day-07')
-rw-r--r-- | 2020/day-07/day-07.rkt | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/2020/day-07/day-07.rkt b/2020/day-07/day-07.rkt index 6ad63e5..f2a1ffe 100644 --- a/2020/day-07/day-07.rkt +++ b/2020/day-07/day-07.rkt @@ -1,10 +1,10 @@ #lang racket -(require "../../jj-aoc.rkt" +(require advent-of-code threading rebellion/collection/entry rebellion/collection/multidict) -(define raw-rules (~> (open-day 7 2020) (port->string) (string-split "\n"))) +(define raw-rules (~> (open-aoc-input (find-session) 2020 7) (port->string) (string-split "\n"))) (define (split-rule r) (match-define (list head tail) (string-split (string-trim r #px" bags?.") " bags contain ")) @@ -20,10 +20,9 @@ (define rules-multidict (for*/multidict ([ln (in-list raw-rules)] #:do [(match-define (list* from tos) (split-rule ln))] [to (in-list tos)]) - (entry from to))) + (entry from to))) ;; part 1 - (define (bags-that-eventually-contain target) (for/fold ([holders (set)]) ([rule (in-multidict-entries rules-multidict)]) (match rule @@ -31,14 +30,17 @@ (set-union (set-add holders outside) (bags-that-eventually-contain outside))] [_ holders]))) -(time (set-count (bags-that-eventually-contain '|shiny gold|))) +(define part-1 (set-count (bags-that-eventually-contain '|shiny gold|))) +(~a "Part 1: " part-1) +;; (aoc-submit (find-session) 2020 7 1 part-1) ;; part 2 - (define (bags-that-are-contained-by target) (for/sum ([holding (in-multidict-entries rules-multidict)]) (match holding [(entry (== target) (list held n)) (+ n (* n (bags-that-are-contained-by held)))] [_ 0]))) -(time (bags-that-are-contained-by '|shiny gold|)) +(define part-2 (bags-that-are-contained-by '|shiny gold|)) +(~a "Part 2: " part-2) +;; (aoc-submit (find-session) 2020 7 1 part-2) |