Skip to content

Commit 616ed1a

Browse files
committed
Add exercise: killer-sudoku-helper
This upstreams the killer-sudoku-helper practice exercise from the Julia track.
1 parent 2675078 commit 616ed1a

File tree

4 files changed

+323
-0
lines changed

4 files changed

+323
-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: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
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": [
19+
[
20+
1
21+
]
22+
]
23+
},
24+
{
25+
"uuid": "4645da19-9fdd-4087-a910-a6ed66823563",
26+
"description": "2",
27+
"property": "combinations",
28+
"input": {
29+
"cage": {
30+
"sum": 2,
31+
"size": 2,
32+
"exclude": []
33+
}
34+
},
35+
"expected": [
36+
[
37+
2
38+
]
39+
]
40+
},
41+
{
42+
"uuid": "07cfc704-f8aa-41b2-8f9a-cbefb674cb48",
43+
"description": "3",
44+
"property": "combinations",
45+
"input": {
46+
"cage": {
47+
"sum": 3,
48+
"size": 3,
49+
"exclude": []
50+
}
51+
},
52+
"expected": [
53+
[
54+
3
55+
]
56+
]
57+
},
58+
{
59+
"uuid": "22b8b2ba-c4fd-40b3-b1bf-40aa5e7b5f24",
60+
"description": "4",
61+
"property": "combinations",
62+
"input": {
63+
"cage": {
64+
"sum": 4,
65+
"size": 4,
66+
"exclude": []
67+
}
68+
},
69+
"expected": [
70+
[
71+
4
72+
]
73+
]
74+
},
75+
{
76+
"uuid": "b75d16e2-ff9b-464d-8578-71f73094cea7",
77+
"description": "5",
78+
"property": "combinations",
79+
"input": {
80+
"cage": {
81+
"sum": 5,
82+
"size": 5,
83+
"exclude": []
84+
}
85+
},
86+
"expected": [
87+
[
88+
5
89+
]
90+
]
91+
},
92+
{
93+
"uuid": "bcbf5afc-4c89-4ff6-9357-07ab4d42788f",
94+
"description": "6",
95+
"property": "combinations",
96+
"input": {
97+
"cage": {
98+
"sum": 6,
99+
"size": 6,
100+
"exclude": []
101+
}
102+
},
103+
"expected": [
104+
[
105+
6
106+
]
107+
]
108+
},
109+
{
110+
"uuid": "511b3bf8-186f-4e35-844f-c804d86f4a7a",
111+
"description": "7",
112+
"property": "combinations",
113+
"input": {
114+
"cage": {
115+
"sum": 7,
116+
"size": 7,
117+
"exclude": []
118+
}
119+
},
120+
"expected": [
121+
[
122+
7
123+
]
124+
]
125+
},
126+
{
127+
"uuid": "bd09a60d-3aca-43bd-b6aa-6ccad01bedda",
128+
"description": "8",
129+
"property": "combinations",
130+
"input": {
131+
"cage": {
132+
"sum": 8,
133+
"size": 8,
134+
"exclude": []
135+
}
136+
},
137+
"expected": [
138+
[
139+
8
140+
]
141+
]
142+
},
143+
{
144+
"uuid": "9b539f27-44ea-4ff8-bd3d-c7e136bee677",
145+
"description": "9",
146+
"property": "combinations",
147+
"input": {
148+
"cage": {
149+
"sum": 9,
150+
"size": 9,
151+
"exclude": []
152+
}
153+
},
154+
"expected": [
155+
[
156+
9
157+
]
158+
]
159+
}
160+
]
161+
},
162+
{
163+
"uuid": "0a8b2078-b3a4-4dbd-be0d-b180f503d5c3",
164+
"description": "Cage with sum 45 contains all digits 1:9",
165+
"property": "combinations",
166+
"input": {
167+
"cage": {
168+
"sum": 45,
169+
"size": 9,
170+
"exclude": []
171+
}
172+
},
173+
"expected": [
174+
[
175+
1,
176+
2,
177+
3,
178+
4,
179+
5,
180+
6,
181+
7,
182+
8,
183+
9
184+
]
185+
]
186+
},
187+
{
188+
"uuid": "2635d7c9-c716-4da1-84f1-c96e03900142",
189+
"description": "Cage with only 1 possible combination",
190+
"property": "combinations",
191+
"input": {
192+
"cage": {
193+
"sum": 7,
194+
"size": 3,
195+
"exclude": []
196+
}
197+
},
198+
"expected": [
199+
[
200+
1,
201+
2,
202+
4
203+
]
204+
]
205+
},
206+
{
207+
"uuid": "a5bde743-e3a2-4a0c-8aac-e64fceea4228",
208+
"description": "Cage with several combinations",
209+
"property": "combinations",
210+
"input": {
211+
"cage": {
212+
"sum": 10,
213+
"size": 2,
214+
"exclude": []
215+
}
216+
},
217+
"expected": [
218+
[
219+
1,
220+
9
221+
],
222+
[
223+
2,
224+
8
225+
],
226+
[
227+
3,
228+
7
229+
],
230+
[
231+
4,
232+
6
233+
]
234+
]
235+
},
236+
{
237+
"uuid": "dfbf411c-737d-465a-a873-ca556360c274",
238+
"description": "Cage with several combinations that is restricted",
239+
"property": "combinations",
240+
"input": {
241+
"cage": {
242+
"sum": 10,
243+
"size": 2,
244+
"exclude": [
245+
1,
246+
4
247+
]
248+
}
249+
},
250+
"expected": [
251+
[
252+
2,
253+
8
254+
],
255+
[
256+
3,
257+
7
258+
]
259+
]
260+
}
261+
]
262+
}
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+
![https://media.githubusercontent.com/media/exercism/v3-files/main/julia/killer-sudoku-helper/example1.png](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+
![https://media.githubusercontent.com/media/exercism/v3-files/main/julia/killer-sudoku-helper/example2.png](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+
![https://media.githubusercontent.com/media/exercism/v3-files/main/julia/killer-sudoku-helper/example3.png](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)