Day 1
This commit is contained in:
commit
d872061ff3
|
@ -0,0 +1,4 @@
|
||||||
|
.session
|
||||||
|
*.rkt~
|
||||||
|
input.*.txt
|
||||||
|
.envrc
|
|
@ -0,0 +1,17 @@
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(define input (file->list "input.1.txt"))
|
||||||
|
|
||||||
|
(define (mass->fuel mass)
|
||||||
|
(- (floor (/ mass 3)) 2))
|
||||||
|
|
||||||
|
; part 1
|
||||||
|
(displayln (foldr + 0 (map mass->fuel input)))
|
||||||
|
|
||||||
|
(define (mass->fuel* mass)
|
||||||
|
(let ([fuel (mass->fuel mass)])
|
||||||
|
(cond [(<= fuel 0) 0]
|
||||||
|
[else (+ fuel (mass->fuel* fuel))])))
|
||||||
|
|
||||||
|
; part 2
|
||||||
|
(displayln (foldr + 0 (map mass->fuel* input)))
|
Loading…
Reference in New Issue