aboutsummaryrefslogtreecommitdiff
path: root/racket/aoc2023/day-24/day-24b.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 /racket/aoc2023/day-24/day-24b.rkt
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'racket/aoc2023/day-24/day-24b.rkt')
-rw-r--r--racket/aoc2023/day-24/day-24b.rkt37
1 files changed, 37 insertions, 0 deletions
diff --git a/racket/aoc2023/day-24/day-24b.rkt b/racket/aoc2023/day-24/day-24b.rkt
new file mode 100644
index 0000000..b106b30
--- /dev/null
+++ b/racket/aoc2023/day-24/day-24b.rkt
@@ -0,0 +1,37 @@
+#lang rosette
+
+(require advent-of-code
+ threading)
+
+(struct hail (posn vel))
+(struct posn (x y z))
+(struct vel (x y z))
+
+(define input (fetch-aoc-input (find-session) 2023 24 #:cache #true))
+
+(define (->struct f str)
+ (~> str (string-split _ ",") (map (λ~> string-trim string->number) _) (apply f _)))
+
+(define (parse-hail-record str)
+ (match-define (list p v) (string-split str " @ "))
+ (hail (->struct posn p) (->struct vel v)))
+
+(define hail-paths
+ (for/list ([hail (in-list (string-split input "\n"))] ;
+ [_ (in-range 3)])
+ (parse-hail-record hail)))
+
+;; part 1 - see day-24a.rkt
+;; part 2
+
+(define-symbolic px py pz vx vy vz integer?)
+
+(define sol
+ (solve ;
+ (for ([path (in-list hail-paths)])
+ (define-symbolic* t integer?)
+ (assert (= (+ px (* vx t)) (+ (~> path hail-posn posn-x) (* (~> path hail-vel vel-x) t))))
+ (assert (= (+ py (* vy t)) (+ (~> path hail-posn posn-y) (* (~> path hail-vel vel-y) t))))
+ (assert (= (+ pz (* vz t)) (+ (~> path hail-posn posn-z) (* (~> path hail-vel vel-z) t)))))))
+
+(evaluate (+ px py pz) sol)