This commit is contained in:
Jonathan Chan 2021-12-05 22:02:31 -08:00
parent 2e4c2e3f36
commit a813e9b2fa
2 changed files with 29 additions and 0 deletions

1
input/06.txt Normal file
View File

@ -0,0 +1 @@
3,5,2,5,4,3,2,2,3,5,2,3,2,2,2,2,3,5,3,5,5,2,2,3,4,2,3,5,5,3,3,5,2,4,5,4,3,5,3,2,5,4,1,1,1,5,1,4,1,4,3,5,2,3,2,2,2,5,2,1,2,2,2,2,3,4,5,2,5,4,1,3,1,5,5,5,3,5,3,1,5,4,2,5,3,3,5,5,5,3,2,2,1,1,3,2,1,2,2,4,3,4,1,3,4,1,2,2,4,1,3,1,4,3,3,1,2,3,1,3,4,1,1,2,5,1,2,1,2,4,1,3,2,1,1,2,4,3,5,1,3,2,1,3,2,3,4,5,5,4,1,3,4,1,2,3,5,2,3,5,2,1,1,5,5,4,4,4,5,3,3,2,5,4,4,1,5,1,5,5,5,2,2,1,2,4,5,1,2,1,4,5,4,2,4,3,2,5,2,2,1,4,3,5,4,2,1,1,5,1,4,5,1,2,5,5,1,4,1,1,4,5,2,5,3,1,4,5,2,1,3,1,3,3,5,5,1,4,1,3,2,2,3,5,4,3,2,5,1,1,1,2,2,5,3,4,2,1,3,2,5,3,2,2,3,5,2,1,4,5,4,4,5,5,3,3,5,4,5,5,4,3,5,3,5,3,1,3,2,2,1,4,4,5,2,2,4,2,1,4

28
src/06.rkt Normal file
View File

@ -0,0 +1,28 @@
#lang curly-fn racket
(require "../lib.rkt")
(define input
(~> (problem-input 6)
first
string-csv
(map string->number _)))
(define assocf ( cdr assoc))
(define fish
(for/list ([age (range 0 9)])
(cons age (count #{= % age} input))))
(define (tick days)
(for/fold ([fish fish]
#:result (sum (map cdr fish)))
([_ (range days)])
(for/list ([age (range 0 9)])
(match age
[6 (cons age (+ (assocf 0 fish)
(assocf 7 fish)))]
[8 (cons age (assocf 0 fish))]
[_ (cons age (assocf (add1 age) fish))]))))
(show-solution (tick 80) (tick 256))