Skip to content

fix : invert blank_row_from_bottom calculation in Number-Sliding-Puzzle is_solvable #1844

Description

@tmdeveloper007

Summary of What Needs to be Done

The is_solvable function in games/Number-Sliding-Puzzle/Number-Sliding-Puzzle.py computes blank_row_from_bottom incorrectly. It uses 3 - blank_row_from_top which gives wrong values for the bottom row. The formula for a 3x3 sliding puzzle is: solvable if (inversions + blank_row_from_bottom) is odd, where blank_row_from_bottom should be 1 for bottom, 2 for middle, 3 for top.

Changes that Need to be Made

  • Change blank_row_from_bottom = 3 - blank_row_from_top to blank_row_from_bottom = 3 - (blank_idx // 3) or equivalently blank_row_from_bottom = blank_row_from_top + 1

Impact that it would Provide

  • Fixes incorrect solvability checks for certain 8-puzzle configurations
  • Prevents valid puzzles from being incorrectly rejected as unsolvable

Note: Please assign this issue to the tmdeveloper007 account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions