Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
6
2022/day02/day02.bqn
Normal file
6
2022/day02/day02.bqn
Normal file
|
@ -0,0 +1,6 @@
|
|||
in←|>"AX"⊸-¨0‿2⊸⊏¨•FLines⊑•args
|
||||
ShapeScore←{+´1+1⊏˘𝕩}
|
||||
WinScore←{+´3×3⊸|1+-˜´˘𝕩}
|
||||
•Show (ShapeScore+WinScore)in
|
||||
in2←(3⊸|∘⊏˘in+¯1⊸+)⌾(1⊸⊏˘)in
|
||||
•Show (ShapeScore+WinScore)in2
|
52
2022/day02/day02.rkt
Normal file
52
2022/day02/day02.rkt
Normal file
|
@ -0,0 +1,52 @@
|
|||
#lang racket
|
||||
|
||||
(require threading)
|
||||
|
||||
(define (read-input filename)
|
||||
(for/list ([l (in-lines (open-input-file filename))])
|
||||
(map string->symbol (string-split l))))
|
||||
|
||||
(define (win-score round)
|
||||
(~> (- (cadr round) (car round))
|
||||
(+ 1 _)
|
||||
(modulo _ 3)
|
||||
(* 3 _)))
|
||||
|
||||
(define (shape-score round)
|
||||
(+ 1 (cadr round)))
|
||||
|
||||
(define (read-play s)
|
||||
(match s
|
||||
['A 0]
|
||||
['B 1]
|
||||
['C 2]
|
||||
['X 0]
|
||||
['Y 1]
|
||||
['Z 2]
|
||||
[_ (error "unrecognized symbol" s)]))
|
||||
|
||||
(define (part1 in)
|
||||
(for/sum ([round in])
|
||||
(let ([round (map read-play round)])
|
||||
(+ (shape-score round) (win-score round)))))
|
||||
|
||||
(define (choose-play round)
|
||||
(define them (read-play (car round)))
|
||||
(define us
|
||||
(modulo
|
||||
(match (cadr round)
|
||||
['X (- them 1)]
|
||||
['Y them]
|
||||
['Z (+ them 1)]
|
||||
[_ (error "unexpected symbol" (cadr round))])
|
||||
3))
|
||||
(list them us))
|
||||
|
||||
(define (part2 in)
|
||||
(for/sum ([round in])
|
||||
(let ([round (choose-play round)])
|
||||
(+ (shape-score round) (win-score round)))))
|
||||
|
||||
(define in (read-input "input"))
|
||||
(displayln (part1 in))
|
||||
(displayln (part2 in))
|
2500
2022/day02/input
Normal file
2500
2022/day02/input
Normal file
File diff suppressed because it is too large
Load diff
3
2022/day02/test
Normal file
3
2022/day02/test
Normal file
|
@ -0,0 +1,3 @@
|
|||
A Y
|
||||
B X
|
||||
C Z
|
Loading…
Add table
Add a link
Reference in a new issue