|
| 1 | +# Instructions |
| 2 | + |
| 3 | +A friend of yours is learning how to solve Killer Sudokus (rules below) but struggling to figure out which digits can go in a cage. |
| 4 | +They ask you to help them out by writing a small program that lists all valid combinations for a given cage, and any constraints that affect the cage. |
| 5 | + |
| 6 | +To make the output of your program easy to read, the combinations it returns must be sorted. |
| 7 | + |
| 8 | +## Killer Sudoku Rules |
| 9 | + |
| 10 | +- [Standard Sudoku rules][sudoku-rules] apply. |
| 11 | +- The digits in a cage, usually marked by a dotted line, add up to the small number given in the corner of the cage. |
| 12 | +- A digit may only occur once in a cage. |
| 13 | + |
| 14 | +For a more detailed explanation, check out [this guide][killer-guide]. |
| 15 | + |
| 16 | +## Example 1: Cage with only 1 possible combination |
| 17 | + |
| 18 | +In a 3-digit cage with a sum of 7, there is only one valid combination: 124. |
| 19 | + |
| 20 | +- 1 + 2 + 4 = 7 |
| 21 | +- Any other combination that adds up to 7, e.g. 232, would violate the rule of not repeating digits within a cage. |
| 22 | + |
| 23 | +![Sudoku grid, with three killer cages that are marked as grouped together. |
| 24 | +The first killer cage is in the 3×3 box in the top left corner of the grid. |
| 25 | +The middle column of that box forms the cage, with the followings cells from top to bottom: first cell contains a 1 and a pencil mark of 7, indicating a cage sum of 7, second cell contains a 2, third cell contains a 5. |
| 26 | +The numbers are highlighted in red to indicate a mistake. |
| 27 | +The second killer cage is in the central 3×3 box of the grid. |
| 28 | +The middle column of that box forms the cage, with the followings cells from top to bottom: first cell contains a 1 and a pencil mark of 7, indicating a cage sum of 7, second cell contains a 2, third cell contains a 4. |
| 29 | +None of the numbers in this cage are highlighted and therefore don't contain any mistakes. |
| 30 | +The third killer cage follows the outside corner of the central 3×3 box of the grid. |
| 31 | +It is made up of the following three cells: the top left cell of the cage contains a 2, highlighted in red, and a cage sum of 7. |
| 32 | +The top right cell of the cage contains a 3. |
| 33 | +The bottom right cell of the cage contains a 2, highlighted in red. All other cells are empty.][one-solution-img] |
| 34 | + |
| 35 | +## Example 2: Cage with several combinations |
| 36 | + |
| 37 | +In a 2-digit cage with a sum 10, there are 4 possible combinations: |
| 38 | + |
| 39 | +- 19 |
| 40 | +- 28 |
| 41 | +- 37 |
| 42 | +- 46 |
| 43 | + |
| 44 | +![Sudoku grid, all squares empty except for the middle column, column 5, which has 8 rows filled. |
| 45 | +Each continguous two rows form a killer cage and are marked as grouped together. |
| 46 | +From top to bottom: first group is a cell with value 1 and a pencil mark indicating a cage sum of 10, cell with value 9. |
| 47 | +Second group is a cell with value 2 and a pencil mark of 10, cell with value 8. |
| 48 | +Third group is a cell with value 3 and a pencil mark of 10, cell with value 7. |
| 49 | +Fourth group is a cell with value 4 and a pencil mark of 10, cell with value 6. |
| 50 | +The last cell in the column is empty.][four-solutions-img] |
| 51 | + |
| 52 | +## Example 3: Cage with several combinations that is restricted |
| 53 | + |
| 54 | +In a 2-digit cage with a sum 10, where the column already contains a 1 and a 4, there are 2 possible combinations: |
| 55 | + |
| 56 | +- 28 |
| 57 | +- 37 |
| 58 | + |
| 59 | +19 and 46 are not possible due to the 1 and 4 in the column according to standard Sudoku rules. |
| 60 | + |
| 61 | +![Sudoku grid, all squares empty except for the middle column, column 5, which has 8 rows filled. |
| 62 | +The first row contains a 4, the second is empty, and the third contains a 1. |
| 63 | +The 1 is highlighted in red to indicate a mistake. |
| 64 | +The last 6 rows in the column form killer cages of two cells each. |
| 65 | +From top to bottom: first group is a cell with value 2 and a pencil mark indicating a cage sum of 10, cell with value 8. |
| 66 | +Second group is a cell with value 3 and a pencil mark of 10, cell with value 7. |
| 67 | +Third group is a cell with value 1, highlighted in red, and a pencil mark of 10, cell with value 9.][not-possible-img] |
| 68 | + |
| 69 | +## Trying it yourself |
| 70 | + |
| 71 | +If you want to give an approachable Killer Sudoku a go, you can try out [this puzzle][clover-puzzle] by Clover, featured by [Mark Goodliffe on Cracking The Cryptic on the 21st of June 2021][goodliffe-video]. |
| 72 | + |
| 73 | +You can also find Killer Sudokus in varying difficulty in numerous newspapers, as well as Sudoku apps, books and websites. |
| 74 | + |
| 75 | +## Credit |
| 76 | + |
| 77 | +The screenshots above have been generated using [F-Puzzles.com](https://www.f-puzzles.com/), a Puzzle Setting Tool by Eric Fox. |
| 78 | + |
| 79 | +[sudoku-rules]: https://masteringsudoku.com/sudoku-rules-beginners/ |
| 80 | +[killer-guide]: https://masteringsudoku.com/killer-sudoku/ |
| 81 | +[one-solution-img]: https://assets.exercism.org/images/exercises/killer-sudoku-helper/example1.png |
| 82 | +[four-solutions-img]: https://assets.exercism.org/images/exercises/killer-sudoku-helper/example2.png |
| 83 | +[not-possible-img]: https://assets.exercism.org/images/exercises/killer-sudoku-helper/example3.png |
| 84 | +[clover-puzzle]: https://app.crackingthecryptic.com/sudoku/HqTBn3Pr6R |
| 85 | +[goodliffe-video]: https://youtu.be/c_NjEbFEeW0?t=1180 |
0 commit comments