Skip to content

Uniqueness scoped to the wrong dimension

write-from-scratch / multi-constraint / array / tool-limitation

Making each row’s cells differ leaves the columns free to repeat. Adding the same check per column still isn’t grid-unique: two cells that share neither a row nor a column, such as the ends of a diagonal, are never compared. The only sure way is to compare every pair of cells.

unique{} isn’t used on purpose: on the current toolchain, unique{} over a row of a 2D array crashes the compiler. Pairwise != works.

Fix the class below.

Requirements

  1. Every core_power[i][j] is between 1 and 9, inclusive.
  2. All 9 values are different from each other across the whole grid. Compare every pair.
  3. Every row sums to exactly 15.
  4. Every column sums to exactly 15.
  5. Both main diagonals sum to exactly 15.

No array-reduction methods (sum() with, find() with): plain expressions and index-based foreach only.

Source on GitHub

thermal_power_fuzzer.sv