This commit is contained in:
xenia 2022-12-31 14:13:18 -05:00
parent f8ad83587f
commit 2edf73b2ae
2 changed files with 176 additions and 0 deletions

38
10.rkt Normal file
View File

@ -0,0 +1,38 @@
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 10
(define (part1 input)
(define *ticks* '(20 60 100 140 180 220))
(for/sum ([tick (in-list *ticks*)])
(* tick (list-ref input (sub1 tick)))))
(define (part2 input)
(define *width* 40)
(define screen
(for/list ([rX (in-list input)] [tick (in-naturals)])
(define h-pixel (remainder tick *width*))
(if (<= (sub1 h-pixel) rX (add1 h-pixel)) #\# #\.)))
(for ([chunk (in-slice *width* screen)])
(displayln (list->string chunk)))
"EALGULPG")
(define (parse fname)
(for/fold ([rX 1] [rX-values '()] #:result (reverse rX-values))
([line (in-list (file->lines fname))])
(match line
[(pregexp #px"^noop") (values rX (cons rX rX-values))]
[(pregexp #px"^addx ([0-9\\-]+)" (list _ (app string->number num)))
(values (+ rX num) (list* rX rX rX-values))])))
(module+ main
(define input (parse "inputs/10"))
(answer 10 1 (time (part1 input)))
(answer 10 2 (time (part2 input)))
(displayln "meow"))

138
inputs/10 Normal file
View File

@ -0,0 +1,138 @@
addx 1
addx 5
noop
addx -1
noop
addx 3
addx 29
addx -1
addx -21
addx 5
noop
addx -20
addx 21
addx 2
addx 8
addx -1
noop
noop
noop
noop
addx 6
addx -1
addx -37
addx 40
addx -10
addx -25
addx 5
addx 2
addx 5
noop
noop
noop
addx 21
addx -20
addx 2
noop
addx 3
addx 2
addx -5
addx 12
addx 3
noop
addx 2
addx 3
addx -2
addx -37
addx 1
addx 5
addx 3
addx -2
addx 2
addx 29
addx -22
addx 13
noop
addx -8
addx -6
addx 7
addx 2
noop
addx 7
addx -2
addx 5
addx 2
addx -26
addx -11
noop
noop
addx 6
addx 1
addx 1
noop
addx 4
addx 5
noop
noop
addx -2
addx 3
noop
addx 2
addx 5
addx 2
addx -22
addx 27
addx -1
addx 1
addx 5
addx 2
noop
addx -39
addx 22
noop
addx -15
addx 3
addx -2
addx 2
addx -2
addx 9
addx 3
noop
addx 2
addx 3
addx -2
addx 2
noop
noop
noop
addx 5
addx -17
addx 24
addx -7
addx 8
addx -36
addx 2
addx 3
addx 33
addx -32
addx 4
addx 1
noop
addx 5
noop
noop
addx 20
addx -15
addx 4
noop
addx 1
noop
addx 4
addx 6
addx -30
addx 30
noop
noop
noop
noop
noop