Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehjohn committed Apr 8, 2024
1 parent 1f9803d commit bb7551f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
12 changes: 7 additions & 5 deletions src/Sudoku/Extensions/IntArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ public static void DumpToConsole(this int[] array, int left = -1, int top = -1)
}

Console.WriteLine(" │");
if (y is 2 or 5)

if (y is not (2 or 5))
{
SetPosition(left, top, line++);

Console.WriteLine("├───────┼───────┼───────┤");
continue;
}

SetPosition(left, top, line++);

Console.WriteLine("├───────┼───────┼───────┤");
}

SetPosition(left, top, line);
Expand Down
20 changes: 12 additions & 8 deletions src/Sudoku/Extensions/SpanIntExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public static bool IsValidSudoku(this Span<int> puzzle)
countRow++;
}

if (puzzle[y + x * 9] != 0)
if (puzzle[y + x * 9] == 0)
{
uniqueColumn.Add(puzzle[y + x * 9]);

countColumn++;
continue;
}

uniqueColumn.Add(puzzle[y + x * 9]);

countColumn++;
}

if (uniqueRow.Count < countRow || uniqueColumn.Count < countColumn)
Expand All @@ -55,12 +57,14 @@ public static bool IsValidSudoku(this Span<int> puzzle)
{
for (var y = 0; y < 3; y++)
{
if (puzzle[(yO + y) * 9 + xO + x] != 0)
if (puzzle[(yO + y) * 9 + xO + x] == 0)
{
uniqueBox.Add(puzzle[(yO + y) * 9 + xO + x]);

countBox++;
continue;
}

uniqueBox.Add(puzzle[(yO + y) * 9 + xO + x]);

countBox++;
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Sudoku/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ private void RemoveCells(int[] puzzle, int cellsToRemove)

for (var i = 0; i < 81; i++)
{
if (puzzle[i] == 0)
if (puzzle[i] != 0)
{
filledCells.Add(i);

puzzle[i] = copy[i];
continue;
}

filledCells.Add(i);

puzzle[i] = copy[i];
}
}
}
Expand Down

0 comments on commit bb7551f

Please sign in to comment.