diff options
author | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
commit | 8ab65dc2da1742eb86ec636c50c7018385b68167 (patch) | |
tree | c4fd556aca9b867cfa1f2f174128c30857353884 /aoc2021/day-06/day-06.rkt | |
parent | fafbeaf9e3c09ba7a5bea7e47d5736001f8a5aa1 (diff) | |
download | gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.tar.gz gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.zip |
prep for 2023, renaming for consistency
Diffstat (limited to 'aoc2021/day-06/day-06.rkt')
-rw-r--r-- | aoc2021/day-06/day-06.rkt | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/aoc2021/day-06/day-06.rkt b/aoc2021/day-06/day-06.rkt new file mode 100644 index 0000000..d8855ba --- /dev/null +++ b/aoc2021/day-06/day-06.rkt @@ -0,0 +1,27 @@ +#lang racket +(require advent-of-code + list-utils + threading + racket/hash) + +(define fish-data + (~> (open-aoc-input (find-session) 2021 6 #:cache (string->path "./cache")) + port->string + string-trim + (string-split ",") + (map string->number _))) + +(define (simulate-fish time-period) + (for/fold ([state (frequencies fish-data)] #:result (~> state hash-values (apply + _))) + ([day (inclusive-range 1 time-period)]) + (define day-older-fish + (for/hash ([(days pop) (in-hash state)]) + (values (sub1 days) pop))) + (define breeding-fish (hash-ref day-older-fish -1 0)) + (hash-union (hash-remove day-older-fish -1) (hash 8 breeding-fish 6 breeding-fish) #:combine +))) + +;; part 1 +(simulate-fish 80) + +;; part 2 +(simulate-fish 256) |