summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.zig9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main.zig b/src/main.zig
index 0e8da4e..e6975be 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,5 +1,4 @@
const SudokuSolver = struct {
- const countEql = std.simd.countElementsWithValue;
const join = std.simd.join;
// Each cell exists in memory three times.
// This makes it easy to compare a guess against all relevant cells simultaneously.
@@ -29,7 +28,9 @@ const SudokuSolver = struct {
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(constraints, @intCast(n)) == 0) {
+ const n_vec: @Vector(@typeInfo(@TypeOf(constraints)).vector.len, u8) = @splat(n);
+ const equals = constraints == n_vec;
+ if (!@reduce(.Or, equals)) {
cell_guesses.set(n - 1);
}
}
@@ -95,7 +96,9 @@ const SudokuSolver = struct {
fn isSolved(self: SudokuSolver) bool {
for (self.rows) |row| {
- if (countEql(row, 0) > 0) return false;
+ const z_vec: @Vector(@typeInfo(@TypeOf(row)).vector.len, u8) = @splat(0);
+ const equals = row == z_vec;
+ if (@reduce(.Or, equals)) return false;
}
return true;
}