diff options
author | J.J <thechairman@thechairman.info> | 2023-12-24 16:20:24 -0500 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2023-12-24 16:20:24 -0500 |
commit | 48c2d7f41a0b6c9bb4279f6ab0ce16c2c94155d8 (patch) | |
tree | aec8e605773283adf69db060f1443557c63cf3d8 /aoc2023-other/day-24/day-24b.rkt | |
parent | 11902b67b519a9096d032f5887a33be4fc3e0b04 (diff) | |
download | gleam_aoc-48c2d7f41a0b6c9bb4279f6ab0ce16c2c94155d8.tar.gz gleam_aoc-48c2d7f41a0b6c9bb4279f6ab0ce16c2c94155d8.zip |
racket day 24 parts 1 and 2 complete
Diffstat (limited to 'aoc2023-other/day-24/day-24b.rkt')
-rw-r--r-- | aoc2023-other/day-24/day-24b.rkt | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/aoc2023-other/day-24/day-24b.rkt b/aoc2023-other/day-24/day-24b.rkt new file mode 100644 index 0000000..38e4317 --- /dev/null +++ b/aoc2023-other/day-24/day-24b.rkt @@ -0,0 +1,34 @@ +#lang rosette + +(require advent-of-code + threading) + +(struct hail (posn vel) #:transparent) +(struct posn (x y z) #:transparent) +(struct vel (x y z) #:transparent) + +(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 p posn) (->struct v vel))) + +(define hail-paths + (for/list ([hail (in-list (string-split input "\n"))] ; + [_ (in-range 3)]) + (parse-hail-record hail))) + +(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) |