In the realm of video game bingo, it is common to use magic squares to generate cards. If you have $25$ difficulty buckets for goals, then if you lay out those buckets onto a magic square, any bingo will be approximately the same difficulty.

I had a related, but distinct problem to solve. I have eight buckets of goals, where each goal is equivalent in difficulty, but only if only one goal is used from each bucket (per potential bingo). Therefore, I need to lay out, on a $5\times 5$ grid, the numbers $[1..8]$ such that no row, column, or diagonal contains a duplicate number.

Maintaining a somewhat even distribution of goals from the eight buckets is ideal, but not required. The solution I ended going with, at least temporarily, was to use a hardcoded quasimagic square and randomly transpose and/or reflect it.

I did spend an evening trying to figure out if there's a procedural way to generate or enumerate all possible boards, though. That's the question I pose here: how can a quasimagic square of this definition be generated? Bonus: how does (or doesn't) the problem change as you increase or decrease the number of buckets?

Here's the example quasimagic square I'm using:

$$ \begin{matrix} 1 & 3 & 5 & 7 & 8 \\ 2 & 4 & 3 & 6 & 5 \\ 4 & 5 & 2 & 3 & 7 \\ 6 & 7 & 4 & 8 & 1 \\ 3 & 2 & 8 & 1 & 6 \end{matrix} $$

  • $\begingroup$ This was a tossup between CompSci.SE and Math.SE for me. It felt more like a math question, thus I put it here. $\endgroup$ – CAD97 Jul 3 '18 at 3:57
  • $\begingroup$ The sum of the numbers from $1$ to $8$ is $36$, so three sets total $108$. To get a magic square the extra number needs to be $2$ because the sum of all five rows is the sum of all the numbers in the square and the sum of a row $22$. I don't know if it is possible $\endgroup$ – Ross Millikan Jul 3 '18 at 4:04
  • $\begingroup$ It's not a real magic square, and I don't think there's a real terminology for what I'm doing, thus why I (try to) call it a quasimagic square most of the time. The example is an example of what I want to generate/enumerate. I care about duplicates, not the sum. It's closer to sudoku, I now realize. @RossMillikan $\endgroup$ – CAD97 Jul 3 '18 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.