diff options
author | Hunky Jimpjorps <thechairman@thechairman.info> | 2024-02-02 17:05:12 -0500 |
---|---|---|
committer | Hunky Jimpjorps <thechairman@thechairman.info> | 2024-02-02 17:05:12 -0500 |
commit | 48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9 (patch) | |
tree | f59a13e0b5e80ab925220b4488c6e36b1bec660a /aoc2023-other/day-15/day-15.rkt | |
parent | 87e9ab25ff70e215b537939a4bc23ab101f41dbe (diff) | |
download | gleam_aoc-48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9.tar.gz gleam_aoc-48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9.zip |
renaming
Diffstat (limited to 'aoc2023-other/day-15/day-15.rkt')
-rw-r--r-- | aoc2023-other/day-15/day-15.rkt | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/aoc2023-other/day-15/day-15.rkt b/aoc2023-other/day-15/day-15.rkt deleted file mode 100644 index d049565..0000000 --- a/aoc2023-other/day-15/day-15.rkt +++ /dev/null @@ -1,41 +0,0 @@ -#lang racket - -(require advent-of-code - threading) - -(define input - (~> (fetch-aoc-input (find-session) 2023 15 #:cache #true) string-trim (string-split ","))) - -(define (hash-algorithm str) - (for/fold ([acc 0]) ([c (in-string str)]) - (~> c char->integer (+ acc) (* 17) (modulo _ 256)))) - -;; part 1 -(for/sum ([code (in-list input)]) (hash-algorithm code)) - -;; part 2 -(define (remove-lens boxes label) - (hash-update boxes - (hash-algorithm label) - (λ (lens-set) (remove label lens-set (λ (rem l) (equal? rem (car l))))) - '())) - -(define (insert-lens boxes label focal) - (define new-lens (cons label focal)) - (hash-update boxes - (hash-algorithm label) - (λ (lens-set) - (if (assoc label lens-set) - (map (λ (pair) (if (equal? (car pair) label) new-lens pair)) lens-set) - (append lens-set (list new-lens)))) - (list new-lens))) - -(define (focusing-power boxes) - (for*/sum ([(box-number lenses) (in-hash boxes)] [(lens order) (in-indexed lenses)]) - (* (add1 box-number) (add1 order) (cdr lens)))) - -(for/fold ([boxes (hash)] #:result (focusing-power boxes)) ([code (in-list input)]) - (match code - [(regexp #rx"(.*)=(.*)" (list _ label (app string->number focal))) - (insert-lens boxes label focal)] - [(regexp #rx"(.*)-" (list _ label)) (remove-lens boxes label)])) |