Since the Sudoku variant puzzles I mentioned below (Kakuro, Killer Sudoku, Str8ts) all have similarities, perhaps it's possible to make a generic puzzle that can use any of the constraints from these variants.
Pencil markings are used to solve all of them, so it would probably be easy to design a UI.
Kakuro has the greatest divergence by removing the restriction of no repeats in a row or column, instead restricting that no repeats can exist within sums.
I would most likely abolish the Kakuro rule since the difference is subtle.
The no repeats in row/column rule feels best represented as a static game rule affecting the entire board and not specific tiles, but this could perhaps even be abstracted away.
Str8ts and Kakuro also both remove the 3x3 squares from Sudoku, but I want the 3x3 squares to be optional.
I also found a bunch of other variants here and here, although most of them would not work well here.
A composite puzzle is inherently inelegant, but I hope that it could lead to great emergent complexity, and the possibility of unique visually patterned puzzles.
Modifiers would apply effects to one or more squares in a contiguous region.
The region doesn't have to be rectangular, e.g. in Killer Sudoku they have strange shapes, but it has to be contiguous because otherwise it's extremely inelegant.
Effects could include:
- No repeats
- Consecutive (Str8ts)
- Non-consecutive (not the opposite of consecutive)
- Sum to given value (Killer Sudoku, Kakuro), inelegant
- Even/odd
- Obstructions (Str8ts, Kakuro), may or may not hold a value
- Multiple numbers fit in a single square
- One number must be double the other (Kropki, 2-size region only)
Since the region is contiguous, requiring all squares in the region to be the same digit is impossible unless we relax the row/column constraint, which is a possibility.
This sudoku.js library is awful (and at least someone noticed), I don't know why it has so many stars.
It seems possible to create my own algorithm, although generating a sudoku puzzle from scratch with a single solution is NP-hard.
A lot of answers online suggest permuting an existing puzzle, which is also a horrible recommendation.
The algorithm used to find solutions is a simple backtracking algorithm that could be easily generalised to include other modifiers, because the rules only apply when it checks to see if the game is solved, something that can easily be computed for any custom rule.
In order to make the solver algorithm efficient, ruling out possibilities using pencil markings would probably be sufficient and would also generalise across any custom rule.
Once you have the solver algorithm, you just have to remove numbers from a solvable puzzle (initially with all numbers filled in) until you reach a state with only one solution.
Since you wouldn't always arrive at a puzzle with one solution, backtracking should be used here as well.
This could be really slow, but I can't tell until I try.
I want it to run in the browser, the speed could also depend on the number and types of modifiers.
I never did Project Euler #96 (probably because it looks inelegant compared to most PE problems), maybe I'll learn more about the puzzle if I try that first.
Actually, the fact that only 50 solutions are required is menacing.
PE problems almost always have performance challenges, and it's 25% difficulty, so maybe the simple backtracking algorithm won't be sufficient.