aoc2022/3.rkt

27 lines
689 B
Racket

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