-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathday06.rkt
45 lines (27 loc) · 783 Bytes
/
day06.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#lang racket
(require "aoc.rkt" threading sugar)
(define (count-fish data)
(for/hash ([i (in-range 1 6)])
(values i (count (curry = i) data))))
(define/caching (offsprings day)
(cond
[(<= day 0) 1]
[else (+ (offsprings (- day 7))
(offsprings (- day 9)))]))
(define (solve data days)
(for/sum ([(day amount) (in-hash data)])
(* amount (offsprings (- days day)))))
(define (parse filename)
(~> (read-input-line filename)
(string-split ",")
(map int _)
count-fish))
(define fish (parse 6))
(solve fish 80)
(solve fish 256)
(module+ test
(require rackunit)
(define fish (parse "06-test"))
(check-equal? (solve fish 18) 26)
(check-equal? (solve fish 80) 5934)
(check-equal? (solve fish 256) 26984457539))