Skip to content

Fail sudoku checks that miss a rule or a unit - #861

Open
RyanJ2002 wants to merge 1 commit into
sysprog21:mainfrom
RyanJ2002:puzzle-grid-single-rule-cases
Open

RyanJ2002 wants to merge 1 commit into
sysprog21:mainfrom
RyanJ2002:puzzle-grid-single-rule-cases

Conversation

@RyanJ2002

@RyanJ2002 RyanJ2002 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Puzzle Grid Save Check (valid-sudoku) let two wrong solutions pass all five built-in cases: one that never checks columns and one that never checks rows. The case labeled duplicate in column also repeats its 8 inside the top-left box, and duplicate in row also repeats its 5 down column 8, so each is refused by a rule the solution kept. Only the box rule had a case of its own, and that one repeats inside the top-left box (#855).

Change

Eight cases built from the valid partial board case are appended, so the variant's example index still points at the same case and the existing five are unchanged. Each of the first six repeats a digit in one unit only and expects false:

  • duplicate in first column only: a 4 at (8,0) repeats the 4 at (4,0) down column 0.
  • duplicate in first row only: a 7 at (0,8) repeats the 7 at (0,4) along row 0.
  • duplicate in last column only: a 1 at (0,8) repeats the 1 at (4,8) down column 8.
  • duplicate in last row only: a 9 at (8,0) repeats the 9 at (8,8) along row 8.
  • duplicate in far box only: a 7 at (6,8) repeats the 7 at (8,7) inside the bottom-right box.
  • duplicate in edge box only: a 7 at (2,3) repeats the 7 at (0,4) inside the top middle box.

With repeats in the first and the last row and column, loops that start at 1 or stop at 8 are refused along with a skipped rule, a check of the top-left box alone is refused by the far box, and a check of only the diagonal or the corner boxes, such as a loop that steps through the boxes by three, by the edge box. Two more expect true:

  • consistent but unsolvable: a 1 at (0,2) repeats nowhere but leaves the board without a completion. The contract does not ask for solvability, and both earlier true cases were solvable, so a validator that also solved the grid passed.
  • fully filled board: a valid completion of valid partial board. Every earlier true case has a blank cell, so a validator that wanted one passed.

Reading order: problem-bank/judges.json for the eight boards, then the new test at the end of the judge tests in tests/browser/compiler-explorer.test.js. It checks every expected value against a check of all three rules, then requires each single-unit case, looked up by label and including the existing duplicate in box only, to reject the wrong check that misses its unit (a skipped rule, loops from 1 or to 8, or only the top-left, diagonal or corner boxes), fully filled board to reject a check that wants a blank cell, and consistent but unsolvable to reject a check that also asks for a completion, found by a small backtracking solver in the test. web/judges/puzzle-grid-save-check.json is the scripts/gen-problems.py output for the same boards (856 of the 1111 added lines), the labels join the tricky-case list in tests/web/contract.rs, and the valid-sudoku digest in tests/golden/task-posed.json is recomputed the way tests/test_task_package.py computes it.

Validation

node --test --test-name-pattern="valid-sudoku cases reject" tests/browser/compiler-explorer.test.js passes. It fails with the built-in cases must keep "duplicate in far box only" against the cases on main, and with "duplicate in first column only" must reject a check that skips the first row and column when that case is given the last-column board, and with "consistent but unsolvable" must reject a check that requires a completion when that board is made solvable with a 4 at (0,2). Of 45 wrong checks (a skipped rule, loops from 1 or to 8, only the top-left, diagonal or corner boxes, a skipped first or last box, three wrong box numberings, a required blank cell, a required completion, always true or false, and each single row, column or box skipped), all fail at least one of the thirteen cases except those that skip one middle row, column or box, which a loop bound does not produce, and a backtracking solver confirms consistent but unsolvable has no completion.

python3 scripts/gen-problems.py --check passes, and so do python3 -m unittest tests.test_gen_problems tests.test_task_package (94 tests), npx prettier --check and npx eslint on the test file.

./scripts/test.sh rust passes on macOS arm64 with GNU coreutils first on PATH. Without it, tasks::defense::attempt_tests::a_model_is_only_one_its_task_built fails on main as well, because its script runs touch -d tomorrow, which the BSD touch refuses; that is unrelated to this change. Not run: cargo-deny (not installed), 3 browser tests that need Playwright, and the portable lane in full on that machine (jq was missing there); the Python and Node checks above cover the files this change touches.

Close #855

cubic-dev-ai[bot]

This comment was marked as resolved.

@sakinu sakinu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both expected values check out (31 and 2499), and 10,000 is the stated upper bound. The open point is the .some(...) thread above, which lets either new case be deleted without failing; the label comment matters once cases are pinned by label.

Comment thread tests/browser/compiler-explorer.test.js Resolved
Comment thread problem-bank/judges.json Resolved

@s4512138 s4512138 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the targeted Sudoku regression on Windows with Node v24.22.0 and checked the counterexamples with CodeTrial’s checkAnswer. The new cases have the expected results. The inline comments cover last-row and last-column indexing and a positive case for a completely filled valid board.

Comment thread problem-bank/judges.json Resolved
Comment thread tests/browser/compiler-explorer.test.js Resolved
jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@RyanJ2002
RyanJ2002 force-pushed the puzzle-grid-single-rule-cases branch from ac8cefd to afc88cb Compare November 26, 2026 06:47
jserv

This comment was marked as resolved.

Puzzle Grid Save Check let a solution pass that never checks columns,
and one that never checks rows: the case labeled duplicate in column
also repeats its 8 inside the top-left box, and the case labeled
duplicate in row also repeats its 5 down column 8, so each is refused by
a rule the solution kept. Eight cases derived from the valid partial
board case close that and the gaps next to it. Four repeat a digit in
one row or column only, in the first and the last of each, so loops that
start at 1 or stop at 8 are refused along with a skipped rule. Two
repeat a digit inside one box only, the bottom-right box and the top
middle one, since the one box case repeats inside the top-left box and a
check of that box alone, or of the diagonal or corner boxes, passed. Two
expect true: a 1 that repeats nowhere but leaves the board without a
completion, because the contract does not ask for solvability and both
earlier true cases were solvable, and a completed board, because every
earlier true case had a blank cell. A test in
tests/browser/compiler-explorer.test.js checks every expected value
against a check of all three rules, requires each single-unit case,
looked up by label, to reject the wrong check that misses its unit,
requires the completed board to reject a check that wants a blank cell,
and the board without a completion to reject a check that also asks for
one, using a small backtracking solver. It fails against the five cases
on main. The labels join the tricky-case list in tests/web/contract.rs,
web/judges/puzzle-grid-save-check.json is regenerated, and the
valid-sudoku digest in tests/golden/task-posed.json is recomputed the
way tests/test_task_package.py computes it.

Close sysprog21#855

Change-Id: Ia8a6ecbec3c6dbcacc80e77af1be00ab9825d9ac
@RyanJ2002
RyanJ2002 force-pushed the puzzle-grid-single-rule-cases branch from afc88cb to 035d4b7 Compare November 26, 2026 09:52
@RyanJ2002 RyanJ2002 changed the title Fail sudoku checks that skip rows or columns Fail sudoku checks that miss a rule or a unit Nov 26, 2026
@github-actions github-actions Bot added the ready for maintainer review The pull request ready for maintainer review. label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: problem bank ready for maintainer review The pull request ready for maintainer review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Puzzle Grid Save Check accepts solutions that skip the row or column rule

4 participants