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

6
2022/day02/day02.bqn Normal file
View file

@ -0,0 +1,6 @@
in|>"AX"-¨02¨•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
View 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

File diff suppressed because it is too large Load diff

3
2022/day02/test Normal file
View file

@ -0,0 +1,3 @@
A Y
B X
C Z