2022-12-03 05:27:31 +00:00
|
|
|
#lang curly-fn racket
|
|
|
|
|
|
|
|
(require "scripts/aoc.rkt")
|
|
|
|
|
|
|
|
;; solution for day 3
|
|
|
|
|
2022-12-03 05:54:12 +00:00
|
|
|
(define (char->prio chr)
|
|
|
|
(- (char->integer chr) (if (char-upper-case? chr) 38 96)))
|
2022-12-03 05:27:31 +00:00
|
|
|
|
|
|
|
(define (part1 input)
|
|
|
|
(for/sum ([line (in-list input)])
|
2022-12-03 05:38:41 +00:00
|
|
|
(define-values [left right] (split-at line (/ (length line) 2)))
|
2022-12-03 05:54:12 +00:00
|
|
|
(~> (set-intersect left right) (set-first) (char->prio))))
|
2022-12-03 05:27:31 +00:00
|
|
|
|
|
|
|
(define (part2 input)
|
2022-12-03 05:54:12 +00:00
|
|
|
(for/sum ([group (in-slice 3 input)])
|
|
|
|
(~> (apply set-intersect group) (set-first) (char->prio))))
|
2022-12-03 05:27:31 +00:00
|
|
|
|
|
|
|
(define (parse fname)
|
2022-12-03 05:38:41 +00:00
|
|
|
(map string->list (file->lines fname)))
|
2022-12-03 05:27:31 +00:00
|
|
|
|
|
|
|
(module+ main
|
|
|
|
(define input (parse "inputs/3"))
|
|
|
|
(answer 3 1 (time (part1 input)))
|
|
|
|
(answer 3 2 (time (part2 input)))
|
|
|
|
(displayln "meow"))
|