diff options
author | HJ <thechairman@thechairman.info> | 2023-12-25 11:24:39 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2023-12-25 11:24:39 -0500 |
commit | 40eb8465f7958ac056a3843d38234848b15464f7 (patch) | |
tree | 6a22b862107f219c6b1c354c4ac70792e9d41ce8 /aoc2023-other/day-20/day-20.rkt | |
parent | f3dfb53b1d59febe1f3bac746150372362f313a9 (diff) | |
download | gleam_aoc-40eb8465f7958ac056a3843d38234848b15464f7.tar.gz gleam_aoc-40eb8465f7958ac056a3843d38234848b15464f7.zip |
day 1-24 end-of-year style cleanup
Diffstat (limited to 'aoc2023-other/day-20/day-20.rkt')
-rw-r--r-- | aoc2023-other/day-20/day-20.rkt | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/aoc2023-other/day-20/day-20.rkt b/aoc2023-other/day-20/day-20.rkt index 6d43192..2e3852d 100644 --- a/aoc2023-other/day-20/day-20.rkt +++ b/aoc2023-other/day-20/day-20.rkt @@ -8,9 +8,9 @@ megaparsack/text) (struct broadcaster ()) -(struct flipflop (state received) #:transparent) -(struct conjunction (recieved) #:transparent) -(struct cable (type dests) #:transparent) +(struct flipflop (state received)) +(struct conjunction (recieved)) +(struct cable (type dests)) (struct nothing ()) (define charlist->symbol (λ~>> (apply string) string->symbol)) @@ -24,7 +24,8 @@ (do (char/p #\&) [name <- (many+/p letter/p)] (pure (cons (charlist->symbol name) (conjunction (hash))))) - (do [name <- (many+/p letter/p)] (pure (cons (charlist->symbol name) (broadcaster))))))) + (do [name <- (many+/p letter/p)] + (pure (cons (charlist->symbol name) (broadcaster))))))) (define cable/p (do [mod <- module/p] @@ -38,22 +39,23 @@ (for/hash ([cable (in-list cables)]) (values (car (cable-type cable)) (cable-dests cable)))) +(define (set-conjunction-initial-state c) + (cond + [(conjunction? (cdr c)) + (~>> destinations + hash-keys + (filter (λ (k) (member (car c) (hash-ref destinations k)))) + (map (λ (k) (cons k 'low))) + (make-immutable-hash) + conjunction + (cons (car c)))] + [else c])) + (define (make-initial-conditions-hash cables) - (~> cables - (map cable-type _) - (map (λ (c) - (cond - [(conjunction? (cdr c)) - (~> destinations - hash-keys - (filter (λ (k) (member (car c) (hash-ref destinations k))) _) - (map (λ (k) (cons k 'low)) _) - (make-immutable-hash) - (conjunction) - (cons (car c) _))] - [else c])) - _) - make-immutable-hash)) + (~>> cables + (map cable-type) + (map set-conjunction-initial-state) + make-immutable-hash)) (define (receive mod from tone) (match mod |