Skip to content

Commit

Permalink
human solver: Minor speed optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 3, 2025
1 parent 122d3eb commit af6a0cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GridLines(
): List<Int> {
val cellIndexesInLines =
cage.cells.mapIndexedNotNull { index, cell ->
if (any { line -> line.contains(cell) }) {
if (cell in cells) {
index
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class SinglePossibleInCage : HumanSolverStrategy {

for (cellNumber in 0..<cage.cells.size) {
if (!cage.getCell(cellNumber).isUserValueSet) {
val differentPossibles = validPossibles.map { it[cellNumber] }.distinct()
val possibles = validPossibles.map { it[cellNumber] }

if (differentPossibles.size == 1) {
if (possibles.isNotEmpty() && (possibles.size == 1 || possibles.none { it != possibles.first() })) {
grid.setUserValueAndRemovePossibles(
cage.getCell(cellNumber),
differentPossibles.single(),
possibles.first(),
)

return true
Expand Down

0 comments on commit af6a0cb

Please sign in to comment.