From 38b3d0d7f8c7235b5397a870fd50c16ff91525aa Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Wed, 14 May 2025 10:21:23 -0400 Subject: Massive speedup with inlining loop --- src/main.zig | 8 +++----- 1 file 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); } } -- cgit