Initial commit

This commit is contained in:
Dimitri Lozeve 2024-11-12 21:43:32 +01:00
commit f242d2b0df
420 changed files with 62521 additions and 0 deletions

28
2022/day03/day03.rkt Normal file
View file

@ -0,0 +1,28 @@
#lang racket
(define (read-input filename)
(map string->list (file->lines filename)))
(define (score items)
(for/sum ([it items])
(cond
[(char-lower-case? it) (- (char->integer it) 96)]
[(char-upper-case? it) (+ 27 (- (char->integer it) 65))])))
(define (part1 in)
(score
(for/list ([l in])
(define-values (a b) (split-at l (/ (length l) 2)))
(car (set-intersect a b)))))
(define (part2 in)
(let lp ([l in]
[res '()])
(match l
['() (score res)]
[(list-rest a b c rest)
(lp rest (cons (car (set-intersect a b c)) res))])))
(define in (read-input "input"))
(displayln (part1 in))
(displayln (part2 in))