Skip to content

Commit 19a4710

Browse files
committed
Upgrade z3
1 parent 2bb67f4 commit 19a4710

5 files changed

Lines changed: 24 additions & 31 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aoc2023/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ petgraph = "0.6.4"
2525
pico-args = "0.5.0"
2626
regex = "1.11.1"
2727
rustworkx-core = "0.13.2"
28-
z3 = { version = "0.13" }
28+
z3 = "0.19"
2929

3030
# Solution dependencies

aoc2023/src/bin/24.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,22 @@ pub fn part_one(input: &str) -> Option<u64> {
9999
pub fn part_two(input: &str) -> Option<u64> {
100100
let stones = input.lines().map(Hailstone::from).collect::<Vec<_>>();
101101

102-
let z3_conf = z3::Config::new();
103-
let ctx = z3::Context::new(&z3_conf);
104-
let solver = z3::Solver::new(&ctx);
102+
let solver = z3::Solver::new();
105103

106-
let x = Int::new_const(&ctx, "x");
107-
let y = Int::new_const(&ctx, "y");
108-
let z = Int::new_const(&ctx, "z");
104+
let x = Int::new_const("x");
105+
let y = Int::new_const("y");
106+
let z = Int::new_const("z");
109107

110-
let vx = Int::new_const(&ctx, "vx");
111-
let vy = Int::new_const(&ctx, "vy");
112-
let vz = Int::new_const(&ctx, "vz");
108+
let vx = Int::new_const("vx");
109+
let vy = Int::new_const("vy");
110+
let vz = Int::new_const("vz");
113111

114112
stones.iter().enumerate().for_each(|(i, hs)| {
115-
let t_intercept = Int::new_const(&ctx, format!("t_{}", i));
113+
let t_intercept = Int::new_const(format!("t_{}", i));
116114

117-
solver.assert(&(&x + &vx * &t_intercept)._eq(&(hs.point.0 + hs.velocity.0 * &t_intercept)));
118-
solver.assert(&(&y + &vy * &t_intercept)._eq(&(hs.point.1 + hs.velocity.1 * &t_intercept)));
119-
solver.assert(&(&z + &vz * &t_intercept)._eq(&(hs.point.2 + hs.velocity.2 * &t_intercept)));
115+
solver.assert(&(&x + &vx * &t_intercept).eq(&(hs.point.0 + hs.velocity.0 * &t_intercept)));
116+
solver.assert(&(&y + &vy * &t_intercept).eq(&(hs.point.1 + hs.velocity.1 * &t_intercept)));
117+
solver.assert(&(&z + &vz * &t_intercept).eq(&(hs.point.2 + hs.velocity.2 * &t_intercept)));
120118
});
121119

122120
let res = solver.check();

aoc2025/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pico-args = "0.5"
2727
regex = "1.11"
2828
tinyjson = "2.5"
2929
tinyvec = "1.8"
30-
z3 = "0.13"
30+
z3 = "0.19"
3131

3232
# Solution dependencies

aoc2025/src/bin/10.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use aoc_utils::*;
22
use itertools::Itertools;
3-
use z3::{
4-
ast::{Ast, Int},
5-
Config, Context, Optimize, SatResult,
6-
};
3+
use z3::{ast::Int, Optimize, SatResult};
74

85
advent_of_code::solution!(10);
96

@@ -66,13 +63,11 @@ pub fn part_one(input: &str) -> Option<u64> {
6663
}
6764

6865
fn solve_part2(buttons: &[Vec<usize>], joltages: &[u64]) -> u64 {
69-
let cfg = Config::new();
70-
let ctx = Context::new(&cfg);
71-
let opt = Optimize::new(&ctx);
66+
let opt = Optimize::new();
7267

7368
// target_counts = number of times to press each button (what we're solving for)
7469
let target_counts: Vec<Int> = (0..buttons.len())
75-
.map(|i| Int::new_const(&ctx, format!("p{i}")))
70+
.map(|i| Int::new_const(format!("p{i}")))
7671
.collect();
7772

7873
// Constraint: (sum of target_counts[i] for all i where pos in buttons[i]) == joltages[pos]
@@ -84,19 +79,19 @@ fn solve_part2(buttons: &[Vec<usize>], joltages: &[u64]) -> u64 {
8479
.map(|(i, _)| &target_counts[i])
8580
.collect();
8681

87-
let sum = Int::add(&ctx, &terms);
88-
opt.assert(&sum._eq(&Int::from_u64(&ctx, jolt)));
82+
let sum = Int::add(&terms);
83+
opt.assert(&sum.eq(&Int::from_u64(jolt)));
8984
}
9085

9186
// Constraint: t >= 0 (can't press a button negative times)
92-
let zero = Int::from_u64(&ctx, 0);
87+
let zero = Int::from_u64(0);
9388
for t in &target_counts {
9489
opt.assert(&t.ge(&zero));
9590
}
9691

9792
// Minimize sum of target_counts
9893
let target_count_refs: Vec<_> = target_counts.iter().collect();
99-
let total = Int::add(&ctx, &target_count_refs);
94+
let total = Int::add(&target_count_refs);
10095
opt.minimize(&total);
10196

10297
// Solve and extract result

0 commit comments

Comments
 (0)