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 /aoc2023-racket/day-01/day-01.rkt | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2023-racket/day-01/day-01.rkt')
-rw-r--r-- | aoc2023-racket/day-01/day-01.rkt | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/aoc2023-racket/day-01/day-01.rkt b/aoc2023-racket/day-01/day-01.rkt deleted file mode 100644 index b720f79..0000000 --- a/aoc2023-racket/day-01/day-01.rkt +++ /dev/null @@ -1,38 +0,0 @@ -#lang racket - -(require advent-of-code - threading) - -(define calibration-values (fetch-aoc-input (find-session) 2023 1)) - -(define (to-number str) - (match (string->number str) - [#false (hash-ref word-to-digit str)] - [n n])) - -(define (parse-calibration-value v valid) - (for/fold ([acc '()] [value v] #:result (+ (to-number (first acc)) (* 10 (to-number (last acc))))) - ([_ (in-naturals)]) - #:break (equal? value "") - (let ([possible-prefix (findf (curry string-prefix? value) valid)]) - (if possible-prefix - (values (cons possible-prefix acc) (substring value 1)) - (values acc (substring value 1)))))) - -(define (total-calibration input valid) - (~> input - (string-trim) - (string-split "\n") - (map (λ~> (parse-calibration-value valid)) _) - (apply + _))) - -;; part 1 - -(define valid-for-part-1 (~> (range 1 10) (map ~a _))) -(total-calibration calibration-values valid-for-part-1) - -;; part 2 -(define word-to-digit - (hash "one" 1 "two" 2 "three" 3 "four" 4 "five" 5 "six" 6 "seven" 7 "eight" 8 "nine" 9)) -(define valid-for-part-2 (append valid-for-part-1 (hash-keys word-to-digit))) -(total-calibration calibration-values valid-for-part-2) |