aboutsummaryrefslogtreecommitdiff
path: root/2021/day-06/day-06.rkt
diff options
context:
space:
mode:
Diffstat (limited to '2021/day-06/day-06.rkt')
-rw-r--r--2021/day-06/day-06.rkt16
1 files changed, 5 insertions, 11 deletions
diff --git a/2021/day-06/day-06.rkt b/2021/day-06/day-06.rkt
index f687db9..d8855ba 100644
--- a/2021/day-06/day-06.rkt
+++ b/2021/day-06/day-06.rkt
@@ -1,6 +1,6 @@
#lang racket
(require advent-of-code
- awesome-list
+ list-utils
threading
racket/hash)
@@ -12,22 +12,16 @@
(map string->number _)))
(define (simulate-fish time-period)
- (for/fold ([state (frequencies fish-data)]
- #:result (~> state
- hash-values
- (apply + _)))
+ (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 +)))
+ (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) \ No newline at end of file
+(simulate-fish 256)