alexandria-ocasio-cortez axiom-of-choice area-of-concern american-orthodox-church almost-optimal-coset solutions in the year of our lord 2021, I guess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
763 B

#lang racket
(require "lib/common.rkt"
threading)
(define (day7a crabs)
(for/min ([align (in-range (add1 (apply max crabs)))])
(for/sum ([crab (in-list crabs)])
(abs (- align crab)))))
(define (day7b crabs)
(define (calculate-fuel crab align)
(define n (abs (- align crab)))
(/ (+ (sqr n) n) 2))
(for/min ([align (in-range (add1 (apply max crabs)))])
(for/sum ([crab (in-list crabs)])
(calculate-fuel crab align))))
(module+ main
(call-with-input-file "data/day7.txt"
(λ (prt)
(define crabs
(~> (port->string prt)
string-split
first
(string-split ",")
(map string->number _)) )
(answer 7 1 (day7a crabs))
(answer 7 2 (day7b crabs)))))