summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2025-05-14 10:21:23 -0400
committerRobby Zambito <contact@robbyzambito.me>2025-05-19 08:16:10 -0400
commit38b3d0d7f8c7235b5397a870fd50c16ff91525aa (patch)
tree07e231da7c4d287ecd7b301e64127a4e9df72f71
parent02d744a861b354d638eec76878bcb0e81ce0ba3c (diff)
Massive speedup with inlining loop
-rw-r--r--src/main.zig8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/main.zig b/src/main.zig
index 0e09d81..2534c17 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -26,12 +26,10 @@ const SudokuSolver = struct {
fn possibleMovesForCell(self: SudokuSolver, row: usize, col: usize) std.StaticBitSet(9) {
var cell_guesses: std.StaticBitSet(9) = .initEmpty();
- for (1..10) |n| {
+ const constraints = join(self.rows[row], join(self.cols[col], self.boxes[boxOf(row, col)]));
+ inline for (1..10) |n| {
// A number is a possible move iff it does not already exist in the current row, col, or box.
- if (countEql(
- join(self.rows[row], join(self.cols[col], self.boxes[boxOf(row, col)])),
- @intCast(n),
- ) == 0) {
+ if (countEql(constraints, @intCast(n)) == 0) {
cell_guesses.set(n - 1);
}
}