From 8ab65dc2da1742eb86ec636c50c7018385b68167 Mon Sep 17 00:00:00 2001 From: "J.J" Date: Thu, 30 Nov 2023 17:10:00 -0500 Subject: prep for 2023, renaming for consistency --- aoc2015/day-03/day-03.rkt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 aoc2015/day-03/day-03.rkt (limited to 'aoc2015/day-03') diff --git a/aoc2015/day-03/day-03.rkt b/aoc2015/day-03/day-03.rkt new file mode 100644 index 0000000..1d44955 --- /dev/null +++ b/aoc2015/day-03/day-03.rkt @@ -0,0 +1,28 @@ +#lang racket +(require "../../jj-aoc.rkt" + threading + (only-in algorithms chunks-of) + racket/hash) + +(define directions + (for/list ([l (in-input-port-chars (open-day 3 2015))]) + (string->symbol (string l)))) + +(define (trace-santa dirs) + (define visits (make-hash)) + (for/fold ([x 0] [y 0] #:result visits) ([dir (in-list dirs)]) + (hash-set! visits `(,x ,y) #true) + (match dir + ['^ (values x (add1 y))] + ['v (values x (sub1 y))] + ['< (values (add1 x) y)] + ['> (values (sub1 x) y)]))) + +;; part 1 +(~> directions trace-santa hash-values length) + +;; part 2 +(~> directions (chunks-of 2) (apply map list _) (map trace-santa _) (match-define (list real robo) _)) + +(hash-union! real robo #:combine (λ _ #true)) +(~> real hash-values length) -- cgit v1.2.3