From bb7551fadc6608a12121eea875401767f3fcfc8b Mon Sep 17 00:00:00 2001 From: Stevo Date: Mon, 8 Apr 2024 14:57:34 +0100 Subject: [PATCH] WIP --- src/Sudoku/Extensions/IntArrayExtensions.cs | 12 +++++++----- src/Sudoku/Extensions/SpanIntExtensions.cs | 20 ++++++++++++-------- src/Sudoku/Generator.cs | 10 ++++++---- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Sudoku/Extensions/IntArrayExtensions.cs b/src/Sudoku/Extensions/IntArrayExtensions.cs index e266b22..f90cc44 100644 --- a/src/Sudoku/Extensions/IntArrayExtensions.cs +++ b/src/Sudoku/Extensions/IntArrayExtensions.cs @@ -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); diff --git a/src/Sudoku/Extensions/SpanIntExtensions.cs b/src/Sudoku/Extensions/SpanIntExtensions.cs index 3be728f..80e55f2 100644 --- a/src/Sudoku/Extensions/SpanIntExtensions.cs +++ b/src/Sudoku/Extensions/SpanIntExtensions.cs @@ -27,12 +27,14 @@ public static bool IsValidSudoku(this Span 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) @@ -55,12 +57,14 @@ public static bool IsValidSudoku(this Span 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++; } } diff --git a/src/Sudoku/Generator.cs b/src/Sudoku/Generator.cs index e3b1dc4..ffc4b17 100644 --- a/src/Sudoku/Generator.cs +++ b/src/Sudoku/Generator.cs @@ -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]; } } }