diff --git a/input/06.txt b/input/06.txt new file mode 100644 index 0000000..66ede3c --- /dev/null +++ b/input/06.txt @@ -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 diff --git a/src/06.rkt b/src/06.rkt new file mode 100644 index 0000000..444ff6e --- /dev/null +++ b/src/06.rkt @@ -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)) \ No newline at end of file