Skip to content

Commit b0dab47

Browse files
committed
twosat super nits
1 parent 2ef3b0a commit b0dab47

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

examples/graphs/two_sat.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@ fn main() {
99
_cnf: String,
1010
n: usize,
1111
m: usize,
12-
clauses: [(i32, i32, usize); m],
12+
clauses: [(isize, isize, usize); m],
1313
}
1414

1515
let mut ts = TwoSat::new(n);
1616

1717
for (x, y, _) in clauses {
1818
let f = x > 0;
1919
let g = y > 0;
20-
ts.add_clause(
21-
x.unsigned_abs() as usize - 1,
22-
f,
23-
y.unsigned_abs() as usize - 1,
24-
g,
25-
);
20+
ts.add_clause(x.unsigned_abs() - 1, f, y.unsigned_abs() - 1, g);
2621
}
2722

2823
let ans = ts.solve();
@@ -31,7 +26,14 @@ fn main() {
3126
println!("s SATISFIABLE");
3227
print!("v");
3328
for i in 1..=n {
34-
print!(" {}", if ans[i - 1] { i as i32 } else { -(i as i32) });
29+
print!(
30+
" {}",
31+
if ans[i - 1] {
32+
i as isize
33+
} else {
34+
-(i as isize)
35+
}
36+
);
3537
}
3638
println!(" 0");
3739
} else {

0 commit comments

Comments
 (0)