aoc2019/1.rkt

18 lines
362 B
Racket

#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)))