Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
36
2021/day06/day06.scm
Normal file
36
2021/day06/day06.scm
Normal file
|
@ -0,0 +1,36 @@
|
|||
(import (chicken io)
|
||||
srfi-1
|
||||
srfi-42
|
||||
srfi-152)
|
||||
|
||||
(define (read-input #!optional (port (current-input-port)))
|
||||
(map string->number (string-split (read-line port) ",")))
|
||||
|
||||
(define (count-fishes in)
|
||||
(define c (make-list 9 0))
|
||||
(do-ec (: x in)
|
||||
(set! (list-ref c x) (add1 (list-ref c x))))
|
||||
c)
|
||||
|
||||
(define (simulate counts days)
|
||||
(if (= 0 days)
|
||||
(take counts 9)
|
||||
(let ((n (car counts)))
|
||||
(set! (list-ref counts 7) (+ n (list-ref counts 7)))
|
||||
(simulate (cdr counts) (- days 1)))))
|
||||
|
||||
(define (total-fishes counts days)
|
||||
(apply + (take (simulate (apply circular-list counts) days) 9)))
|
||||
|
||||
(let* ((in '(3 4 3 1 2))
|
||||
(counts (count-fishes in)))
|
||||
(print "Test:")
|
||||
(print (total-fishes counts 18))
|
||||
(print (total-fishes counts 80))
|
||||
(print (total-fishes counts 256)))
|
||||
|
||||
(print)
|
||||
(let* ((in (read-input))
|
||||
(counts (count-fishes in)))
|
||||
(print (total-fishes counts 80))
|
||||
(print (total-fishes counts 256)))
|
1
2021/day06/input
Normal file
1
2021/day06/input
Normal file
|
@ -0,0 +1 @@
|
|||
3,3,2,1,4,1,1,2,3,1,1,2,1,2,1,1,1,1,1,1,4,1,1,5,2,1,1,2,1,1,1,3,5,1,5,5,1,1,1,1,3,1,1,3,2,1,1,1,1,1,1,4,1,1,1,1,1,1,1,4,1,3,3,1,1,3,1,3,1,2,1,3,1,1,4,1,2,4,4,5,1,1,1,1,1,1,4,1,5,1,1,5,1,1,3,3,1,3,2,5,2,4,1,4,1,2,4,5,1,1,5,1,1,1,4,1,1,5,2,1,1,5,1,1,1,5,1,1,1,1,1,3,1,5,3,2,1,1,2,2,1,2,1,1,5,1,1,4,5,1,4,3,1,1,1,1,1,1,5,1,1,1,5,2,1,1,1,5,1,1,1,4,4,2,1,1,1,1,1,1,1,3,1,1,4,4,1,4,1,1,5,3,1,1,1,5,2,2,4,2,1,1,3,1,5,5,1,1,1,4,1,5,1,1,1,4,3,3,3,1,3,1,5,1,4,2,1,1,5,1,1,1,5,5,1,1,2,1,1,1,3,1,1,1,2,3,1,2,2,3,1,3,1,1,4,1,1,2,1,1,1,1,3,5,1,1,2,1,1,1,4,1,1,1,1,1,2,4,1,1,5,3,1,1,1,2,2,2,1,5,1,3,5,3,1,1,4,1,1,4
|
Loading…
Add table
Add a link
Reference in a new issue