From 8ab65dc2da1742eb86ec636c50c7018385b68167 Mon Sep 17 00:00:00 2001 From: "J.J" Date: Thu, 30 Nov 2023 17:10:00 -0500 Subject: prep for 2023, renaming for consistency --- 2021/day-07/day-07.rkt | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 2021/day-07/day-07.rkt (limited to '2021/day-07') diff --git a/2021/day-07/day-07.rkt b/2021/day-07/day-07.rkt deleted file mode 100644 index 89d5009..0000000 --- a/2021/day-07/day-07.rkt +++ /dev/null @@ -1,28 +0,0 @@ -#lang racket -(require advent-of-code - threading - math/statistics) - -(define crab-data - (~> (open-aoc-input (find-session) 2021 7 #:cache #t) - port->string - string-trim - (string-split ",") - (map string->number _))) - -(define (gauss-sum n) - (/ (* n (+ n 1)) 2)) -(define (compute-fuel-use f crabs align-to) - (for/sum ([crab (in-list crabs)]) (f (abs (- crab align-to))))) - -;; using the fact that the optimum location is at the median -;; of the crabs' starting location for the linear relationship -;; and at a coordinate within 1 unit of the mean for the quadratic one - -(~>> crab-data (median <) (compute-fuel-use identity crab-data)) - -(~>> crab-data - mean - ((λ (m) (list (floor m) (ceiling m)))) - (map (curry compute-fuel-use gauss-sum crab-data)) - (apply min)) -- cgit v1.2.3