diff options
author | Hunky Jimpjorps <thechairman@thechairman.info> | 2022-11-26 01:43:33 -0500 |
---|---|---|
committer | Hunky Jimpjorps <thechairman@thechairman.info> | 2022-11-26 01:43:33 -0500 |
commit | feccf3f6f0a806b3317d1f399e3e8b42945c4f09 (patch) | |
tree | bf15ce045d1106c1b7f7de30c27540f40d0bf947 /2021/day-07/day-07.rkt | |
parent | 8b624fe7d2751337b1f16830cc9c041df73e99e7 (diff) | |
download | gleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.tar.gz gleam_aoc-feccf3f6f0a806b3317d1f399e3e8b42945c4f09.zip |
using raco fmt, replacing missing dependency
Diffstat (limited to '2021/day-07/day-07.rkt')
-rw-r--r-- | 2021/day-07/day-07.rkt | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/2021/day-07/day-07.rkt b/2021/day-07/day-07.rkt index 81a2e4f..89d5009 100644 --- a/2021/day-07/day-07.rkt +++ b/2021/day-07/day-07.rkt @@ -10,21 +10,19 @@ (string-split ",") (map string->number _))) -(define (gauss-sum n) (/ (* n (+ n 1)) 2)) +(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))))) + (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 (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))
\ No newline at end of file + (apply min)) |