diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2021/day-07 | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2021/day-07')
-rw-r--r-- | aoc2021/day-07/day-07.rkt | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/aoc2021/day-07/day-07.rkt b/aoc2021/day-07/day-07.rkt deleted file mode 100644 index 89d5009..0000000 --- a/aoc2021/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)) |