aboutsummaryrefslogtreecommitdiff
path: root/aoc2015/day-06/day-06.rkt
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
committerH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
commit8777ff071f7bb37631baa7b6717ad29961e50911 (patch)
tree6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2015/day-06/day-06.rkt
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'aoc2015/day-06/day-06.rkt')
-rw-r--r--aoc2015/day-06/day-06.rkt49
1 files changed, 0 insertions, 49 deletions
diff --git a/aoc2015/day-06/day-06.rkt b/aoc2015/day-06/day-06.rkt
deleted file mode 100644
index d2eed08..0000000
--- a/aoc2015/day-06/day-06.rkt
+++ /dev/null
@@ -1,49 +0,0 @@
-#lang racket
-(require "../../jj-aoc.rkt"
- threading)
-
-(struct instruction (todo x1 y1 x2 y2) #:transparent)
-
-(define (make-instruction lst)
- (apply instruction (string->symbol (first lst)) (map string->number (rest lst))))
-
-(define instructions
- (for/list ([l (in-lines (open-day 6 2015))])
- (~>> l
- (regexp-match
- #px"(turn on|toggle|turn off) (\\d{1,3}),(\\d{1,3}) through (\\d{1,3}),(\\d{1,3})")
- rest
- make-instruction)))
-
-(define (vector2d-modify! vec x y f)
- (define pos (+ x (* 1000 y)))
- (vector-set! vec pos (f (vector-ref vec pos))))
-
-;; part 1
-(define (todo inst)
- (match (instruction-todo inst)
- ['|turn on| (λ _ #true)]
- ['|turn off| (λ _ #false)]
- ['|toggle| not]))
-
-(define (modify-light-grid inst light-grid using)
- (for ([x (inclusive-range (instruction-x1 inst) (instruction-x2 inst))])
- (for ([y (inclusive-range (instruction-y1 inst) (instruction-y2 inst))])
- (vector2d-modify! light-grid x y (using inst)))))
-
-(define light-grid (make-vector (* 1000 1000) #false))
-(for ([i (in-list instructions)])
- (modify-light-grid i light-grid todo))
-(vector-count identity light-grid)
-
-;; part 2
-(define (todo-dimmer inst)
- (match (instruction-todo inst)
- ['|turn on| add1]
- ['|turn off| (λ (x) (max 0 (sub1 x)))]
- ['|toggle| (curry + 2)]))
-
-(define dimmable-grid (make-vector (* 1000 1000) 0))
-(for ([i (in-list instructions)])
- (modify-light-grid i dimmable-grid todo-dimmer))
-(apply + (vector->list dimmable-grid))