blob: b106b30c08766359712e9b3adfa1431ef4051d80 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)
|