Skip to content

Commit 7cd0ab1

Browse files
SaschaMannSleeplessBytepetertseng
authored
Add exercise: killer-sudoku-helper (#2007)
Co-authored-by: Derk-Jan Karrenbeld <[email protected]> Co-authored-by: Peter Tseng <[email protected]>
1 parent 6373ab6 commit 7cd0ab1

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed

bin/format-array.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
'go-counting' => {
5555
'board' => :multi_line,
5656
},
57+
'killer-sudoku-helper' => {
58+
'expected' => :single_line,
59+
},
5760
'minesweeper' => {
5861
'minefield' => :multi_line_unless_single,
5962
'expected' => :multi_line_unless_single,
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
{
2+
"exercise": "killer-sudoku-helper",
3+
"cases": [
4+
{
5+
"description": "Trivial 1-digit cages",
6+
"cases": [
7+
{
8+
"uuid": "2aaa8f13-11b5-4054-b95c-a906e4d79fb6",
9+
"description": "1",
10+
"property": "combinations",
11+
"input": {
12+
"cage": {
13+
"sum": 1,
14+
"size": 1,
15+
"exclude": []
16+
}
17+
},
18+
"expected": [[1]]
19+
},
20+
{
21+
"uuid": "4645da19-9fdd-4087-a910-a6ed66823563",
22+
"description": "2",
23+
"property": "combinations",
24+
"input": {
25+
"cage": {
26+
"sum": 2,
27+
"size": 1,
28+
"exclude": []
29+
}
30+
},
31+
"expected": [[2]]
32+
},
33+
{
34+
"uuid": "07cfc704-f8aa-41b2-8f9a-cbefb674cb48",
35+
"description": "3",
36+
"property": "combinations",
37+
"input": {
38+
"cage": {
39+
"sum": 3,
40+
"size": 1,
41+
"exclude": []
42+
}
43+
},
44+
"expected": [[3]]
45+
},
46+
{
47+
"uuid": "22b8b2ba-c4fd-40b3-b1bf-40aa5e7b5f24",
48+
"description": "4",
49+
"property": "combinations",
50+
"input": {
51+
"cage": {
52+
"sum": 4,
53+
"size": 1,
54+
"exclude": []
55+
}
56+
},
57+
"expected": [[4]]
58+
},
59+
{
60+
"uuid": "b75d16e2-ff9b-464d-8578-71f73094cea7",
61+
"description": "5",
62+
"property": "combinations",
63+
"input": {
64+
"cage": {
65+
"sum": 5,
66+
"size": 1,
67+
"exclude": []
68+
}
69+
},
70+
"expected": [[5]]
71+
},
72+
{
73+
"uuid": "bcbf5afc-4c89-4ff6-9357-07ab4d42788f",
74+
"description": "6",
75+
"property": "combinations",
76+
"input": {
77+
"cage": {
78+
"sum": 6,
79+
"size": 1,
80+
"exclude": []
81+
}
82+
},
83+
"expected": [[6]]
84+
},
85+
{
86+
"uuid": "511b3bf8-186f-4e35-844f-c804d86f4a7a",
87+
"description": "7",
88+
"property": "combinations",
89+
"input": {
90+
"cage": {
91+
"sum": 7,
92+
"size": 1,
93+
"exclude": []
94+
}
95+
},
96+
"expected": [[7]]
97+
},
98+
{
99+
"uuid": "bd09a60d-3aca-43bd-b6aa-6ccad01bedda",
100+
"description": "8",
101+
"property": "combinations",
102+
"input": {
103+
"cage": {
104+
"sum": 8,
105+
"size": 1,
106+
"exclude": []
107+
}
108+
},
109+
"expected": [[8]]
110+
},
111+
{
112+
"uuid": "9b539f27-44ea-4ff8-bd3d-c7e136bee677",
113+
"description": "9",
114+
"property": "combinations",
115+
"input": {
116+
"cage": {
117+
"sum": 9,
118+
"size": 1,
119+
"exclude": []
120+
}
121+
},
122+
"expected": [[9]]
123+
}
124+
]
125+
},
126+
{
127+
"uuid": "0a8b2078-b3a4-4dbd-be0d-b180f503d5c3",
128+
"description": "Cage with sum 45 contains all digits 1:9",
129+
"property": "combinations",
130+
"input": {
131+
"cage": {
132+
"sum": 45,
133+
"size": 9,
134+
"exclude": []
135+
}
136+
},
137+
"expected": [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
138+
},
139+
{
140+
"uuid": "2635d7c9-c716-4da1-84f1-c96e03900142",
141+
"description": "Cage with only 1 possible combination",
142+
"property": "combinations",
143+
"input": {
144+
"cage": {
145+
"sum": 7,
146+
"size": 3,
147+
"exclude": []
148+
}
149+
},
150+
"expected": [[1, 2, 4]]
151+
},
152+
{
153+
"uuid": "a5bde743-e3a2-4a0c-8aac-e64fceea4228",
154+
"description": "Cage with several combinations",
155+
"property": "combinations",
156+
"input": {
157+
"cage": {
158+
"sum": 10,
159+
"size": 2,
160+
"exclude": []
161+
}
162+
},
163+
"expected": [[1, 9], [2, 8], [3, 7], [4, 6]]
164+
},
165+
{
166+
"uuid": "dfbf411c-737d-465a-a873-ca556360c274",
167+
"description": "Cage with several combinations that is restricted",
168+
"property": "combinations",
169+
"input": {
170+
"cage": {
171+
"sum": 10,
172+
"size": 2,
173+
"exclude": [1, 4]
174+
}
175+
},
176+
"expected": [[2, 8], [3, 7]]
177+
}
178+
]
179+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Description
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](https://masteringsudoku.com/sudoku-rules-beginners/) 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](https://masteringsudoku.com/killer-sudoku/).
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. The first killer cage is in the 3×3 box in the top left corner of the grid. 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. The numbers are highlighted in red to indicate a mistake. The second killer cage is in the central 3×3 box of the grid. 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. None of the numbers in this cage are highlighted and therefore don't contain any mistakes. The third killer cage follows the outside corner of the central 3×3 box of the grid. 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. The top right cell of the cage contains a 3. The bottom right cell of the cage contains a 2, highlighted in red. All other cells are empty.](https://media.githubusercontent.com/media/exercism/v3-files/main/julia/killer-sudoku-helper/example1.png)
24+
25+
## Example 2: Cage with several combinations
26+
27+
In a 2-digit cage with a sum 10, there are 4 possible combinations:
28+
29+
- 19
30+
- 28
31+
- 37
32+
- 46
33+
34+
![Sudoku grid, all squares empty except for the middle column, column 5, which has 8 rows filled. Each continguous two rows form a killer cage and are marked as grouped together. 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. Second group is a cell with value 2 and a pencil mark of 10, cell with value 8. Third group is a cell with value 3 and a pencil mark of 10, cell with value 7. Fourth group is a cell with value 4 and a pencil mark of 10, cell with value 6. The last cell in the column is empty.](https://media.githubusercontent.com/media/exercism/v3-files/main/julia/killer-sudoku-helper/example2.png)
35+
36+
## Example 3: Cage with several combinations that is restricted
37+
38+
In a 2-digit cage with a sum 10, where the column already contains a 1 and a 4, there are 2 possible combinations:
39+
40+
- 28
41+
- 37
42+
43+
19 and 46 are not possible due to the 1 and 4 in the column according to standard Sudoku rules.
44+
45+
![Sudoku grid, all squares empty except for the middle column, column 5, which has 8 rows filled. The first row contains a 4, the second is empty, and the third contains a 1. The 1 is highlighted in red to indicate a mistake. The last 6 rows in the column form killer cages of two cells each. 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. Second group is a cell with value 3 and a pencil mark of 10, cell with value 7. Third group is a cell with value 1, highlighted in red, and a pencil mark of 10, cell with value 9.](https://media.githubusercontent.com/media/exercism/v3-files/main/julia/killer-sudoku-helper/example3.png)
46+
47+
## Trying it yourself
48+
49+
If you want to give an approachable Killer Sudoku a go, you can try out [this puzzle](https://app.crackingthecryptic.com/sudoku/HqTBn3Pr6R) by Clover, featured by [Mark Goodliffe on Cracking The Cryptic on the 21st of June 2021](https://youtu.be/c_NjEbFEeW0?t=1180).
50+
51+
You can also find Killer Sudokus in varying difficulty in numerous newspapers, as well as Sudoku apps, books and websites.
52+
53+
## Credit
54+
55+
The screenshots above have been generated using [F-Puzzles.com](https://www.f-puzzles.com/), a Puzzle Setting Tool by Eric Fox.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
blurb = "Write a tool that makes it easier to solve Killer Sudokus"
2+
source = "Created by Sascha Mann, Jeremy Walker, and BethanyG for the Julia track on Exercism."
3+
source_url = "https://github.com/exercism/julia/pull/413"

0 commit comments

Comments
 (0)