Day 06.
This commit is contained in:
parent
2e4c2e3f36
commit
a813e9b2fa
|
@ -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
|
|
@ -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))
|
Loading…
Reference in New Issue