Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
28
2022/day03/day03.rkt
Normal file
28
2022/day03/day03.rkt
Normal 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))
|
Loading…
Add table
Add a link
Reference in a new issue