diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2022/day-10 | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2022/day-10')
-rw-r--r-- | aoc2022/day-10/day-10.rkt | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/aoc2022/day-10/day-10.rkt b/aoc2022/day-10/day-10.rkt deleted file mode 100644 index 70c80d3..0000000 --- a/aoc2022/day-10/day-10.rkt +++ /dev/null @@ -1,43 +0,0 @@ -#lang racket - -(require advent-of-code - threading - fancy-app - (only-in algorithms chunks-of)) - -(define/match (process-instruction _) - [((list "noop")) (list 'noop)] - [((list "addx" (app string->number val))) (list 'noop (cons 'addx val))]) - -(define instructions - (~> (fetch-aoc-input (find-session) 2022 10) - (string-split "\n") - (map (λ~> string-split process-instruction) _) - (apply append _))) - -;; part 1 -(define interesting-times (inclusive-range 20 220 40)) - -(define/match (evaluate-instruction _op acc) - [('noop _) acc] - [((cons 'addx n) _) (+ acc n)]) - -(for/fold ([acc 1] [interesting-strengths 0] #:result interesting-strengths) - ([inst (in-list instructions)] [i (in-naturals 1)]) - (define new-interesting - (if (member i interesting-times) (+ interesting-strengths (* i acc)) interesting-strengths)) - (values (evaluate-instruction inst acc) new-interesting)) - -;; part 2 -(for/fold ([acc 1] [pixels '()] #:result (~> pixels reverse (chunks-of 40) (map (apply string _) _))) - ([inst (in-list instructions)] [i (in-naturals)]) - (define new-pixel (if (member (modulo i 40) (list (sub1 acc) acc (add1 acc))) #\█ #\space)) - (values (evaluate-instruction inst acc) (cons new-pixel pixels))) - -; for my data set, -; '("███ ████ ████ █ █ ████ ████ █ █ ██ " -; "█ █ █ █ █ █ █ █ █ █ █ █ " -; "█ █ █ ███ ██ ███ ███ ████ █ █ " -; "███ █ █ █ █ █ █ █ █ ████ " -; "█ █ █ █ █ █ █ █ █ █ █ █ " -; "█ █ ████ ████ █ █ ████ █ █ █ █ █ ") |