Skip to content

Commit 42e1614

Browse files
committed
Solve 2023 day 24 part 2 with Python Z3
1 parent 2d9974e commit 42e1614

File tree

2 files changed

+48
-0
lines changed
  • src/main

2 files changed

+48
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from z3 import *
2+
3+
s = Solver()
4+
5+
x, y, z = Reals("x y z")
6+
vx, vy, vz = Reals("vx vy vz")
7+
8+
t0, t1, t2 = Reals("t0 t1 t2")
9+
10+
# s.add(19 + t0 * -2 == x + t0 * vx)
11+
# s.add(13 + t0 * 1 == y + t0 * vy)
12+
# s.add(30 + t0 * -2 == z + t0 * vz)
13+
#
14+
# s.add(18 + t1 * -1 == x + t1 * vx)
15+
# s.add(19 + t1 * -1 == y + t1 * vy)
16+
# s.add(22 + t1 * -2 == z + t1 * vz)
17+
#
18+
# s.add(20 + t2 * -2 == x + t2 * vx)
19+
# s.add(25 + t2 * -2 == y + t2 * vy)
20+
# s.add(34 + t2 * -4 == z + t2 * vz)
21+
22+
s.add(262130794315133 + t0 * 57 == x + t0 * vx)
23+
s.add(305267994111063 + t0 * -252 == y + t0 * vy)
24+
s.add(163273807102793 + t0 * 150 == z + t0 * vz)
25+
26+
s.add(290550702673836 + t1 * -74 == x + t1 * vx)
27+
s.add(186986670515285 + t1 * 19 == y + t1 * vy)
28+
s.add(231769402282435 + t1 * -219 == z + t1 * vz)
29+
30+
s.add(275698513286341 + t2 * -59 == x + t2 * vx)
31+
s.add(162656001312879 + t2 * -24 == y + t2 * vy)
32+
s.add(183065006152383 + t2 * -225 == z + t2 * vz)
33+
34+
print(s.check())
35+
36+
m = s.model()
37+
print(m)
38+

src/main/scala/eu/sim642/adventofcode2023/Day24.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ object Day24 {
5757
inters.size
5858
}
5959

60+
// throw: 6 unk
61+
// per-hailstone: 3 eqs, 1 unk
62+
63+
// 0, 6
64+
// 3, 7
65+
// 6, 8
66+
// 9, 9
67+
6068

6169
def parseHailstone(s: String): Hailstone = s match {
6270
case s"$x, $y, $z @ $vx, $vy, $vz" =>
@@ -71,5 +79,7 @@ object Day24 {
7179

7280
def main(args: Array[String]): Unit = {
7381
println(countIntersections1(parseHailstones(input)))
82+
83+
// part 2: 554668916217145
7484
}
7585
}

0 commit comments

Comments
 (0)