From 481a4dbd66d2d679742ad76318cbb4f06d134fb9 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Thu, 14 Apr 2022 11:53:56 +0200 Subject: [PATCH 1/4] Add exercise: killer-sudoku-helper This upstreams the killer-sudoku-helper practice exercise from the Julia track. --- bin/format-array.rb | 3 + .../killer-sudoku-helper/canonical-data.json | 179 ++++++++++++++++++ exercises/killer-sudoku-helper/description.md | 55 ++++++ exercises/killer-sudoku-helper/metadata.toml | 3 + 4 files changed, 240 insertions(+) create mode 100644 exercises/killer-sudoku-helper/canonical-data.json create mode 100644 exercises/killer-sudoku-helper/description.md create mode 100644 exercises/killer-sudoku-helper/metadata.toml diff --git a/bin/format-array.rb b/bin/format-array.rb index 7d923eed9a..3679694de8 100644 --- a/bin/format-array.rb +++ b/bin/format-array.rb @@ -54,6 +54,9 @@ 'go-counting' => { 'board' => :multi_line, }, + 'killer-sudoku-helper' => { + 'expected' => :single_line, + }, 'minesweeper' => { 'minefield' => :multi_line_unless_single, 'expected' => :multi_line_unless_single, diff --git a/exercises/killer-sudoku-helper/canonical-data.json b/exercises/killer-sudoku-helper/canonical-data.json new file mode 100644 index 0000000000..57270755d4 --- /dev/null +++ b/exercises/killer-sudoku-helper/canonical-data.json @@ -0,0 +1,179 @@ +{ + "exercise": "killer-sudoku-helper", + "cases": [ + { + "description": "Trivial 1-digit cages", + "cases": [ + { + "uuid": "2aaa8f13-11b5-4054-b95c-a906e4d79fb6", + "description": "1", + "property": "combinations", + "input": { + "cage": { + "sum": 1, + "size": 1, + "exclude": [] + } + }, + "expected": [[1]] + }, + { + "uuid": "4645da19-9fdd-4087-a910-a6ed66823563", + "description": "2", + "property": "combinations", + "input": { + "cage": { + "sum": 2, + "size": 2, + "exclude": [] + } + }, + "expected": [[2]] + }, + { + "uuid": "07cfc704-f8aa-41b2-8f9a-cbefb674cb48", + "description": "3", + "property": "combinations", + "input": { + "cage": { + "sum": 3, + "size": 3, + "exclude": [] + } + }, + "expected": [[3]] + }, + { + "uuid": "22b8b2ba-c4fd-40b3-b1bf-40aa5e7b5f24", + "description": "4", + "property": "combinations", + "input": { + "cage": { + "sum": 4, + "size": 4, + "exclude": [] + } + }, + "expected": [[4]] + }, + { + "uuid": "b75d16e2-ff9b-464d-8578-71f73094cea7", + "description": "5", + "property": "combinations", + "input": { + "cage": { + "sum": 5, + "size": 5, + "exclude": [] + } + }, + "expected": [[5]] + }, + { + "uuid": "bcbf5afc-4c89-4ff6-9357-07ab4d42788f", + "description": "6", + "property": "combinations", + "input": { + "cage": { + "sum": 6, + "size": 6, + "exclude": [] + } + }, + "expected": [[6]] + }, + { + "uuid": "511b3bf8-186f-4e35-844f-c804d86f4a7a", + "description": "7", + "property": "combinations", + "input": { + "cage": { + "sum": 7, + "size": 7, + "exclude": [] + } + }, + "expected": [[7]] + }, + { + "uuid": "bd09a60d-3aca-43bd-b6aa-6ccad01bedda", + "description": "8", + "property": "combinations", + "input": { + "cage": { + "sum": 8, + "size": 8, + "exclude": [] + } + }, + "expected": [[8]] + }, + { + "uuid": "9b539f27-44ea-4ff8-bd3d-c7e136bee677", + "description": "9", + "property": "combinations", + "input": { + "cage": { + "sum": 9, + "size": 9, + "exclude": [] + } + }, + "expected": [[9]] + } + ] + }, + { + "uuid": "0a8b2078-b3a4-4dbd-be0d-b180f503d5c3", + "description": "Cage with sum 45 contains all digits 1:9", + "property": "combinations", + "input": { + "cage": { + "sum": 45, + "size": 9, + "exclude": [] + } + }, + "expected": [[1, 2, 3, 4, 5, 6, 7, 8, 9]] + }, + { + "uuid": "2635d7c9-c716-4da1-84f1-c96e03900142", + "description": "Cage with only 1 possible combination", + "property": "combinations", + "input": { + "cage": { + "sum": 7, + "size": 3, + "exclude": [] + } + }, + "expected": [[1, 2, 4]] + }, + { + "uuid": "a5bde743-e3a2-4a0c-8aac-e64fceea4228", + "description": "Cage with several combinations", + "property": "combinations", + "input": { + "cage": { + "sum": 10, + "size": 2, + "exclude": [] + } + }, + "expected": [[1, 9], [2, 8], [3, 7], [4, 6]] + }, + { + "uuid": "dfbf411c-737d-465a-a873-ca556360c274", + "description": "Cage with several combinations that is restricted", + "property": "combinations", + "input": { + "cage": { + "sum": 10, + "size": 2, + "exclude": [1, 4] + } + }, + "expected": [[2, 8], [3, 7]] + } + ] +} diff --git a/exercises/killer-sudoku-helper/description.md b/exercises/killer-sudoku-helper/description.md new file mode 100644 index 0000000000..9a0fd1dc5f --- /dev/null +++ b/exercises/killer-sudoku-helper/description.md @@ -0,0 +1,55 @@ +# Description + +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. +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. + +To make the output of your program easy to read, the combinations it returns must be sorted. + +## Killer Sudoku Rules + +- [Standard Sudoku rules](https://masteringsudoku.com/sudoku-rules-beginners/) apply. +- The digits in a cage, usually marked by a dotted line, add up to the small number given in the corner of the cage. +- A digit may only occur once in a cage. + +For a more detailed explanation, check out [this guide](https://masteringsudoku.com/killer-sudoku/). + +## Example 1: Cage with only 1 possible combination + +In a 3-digit cage with a sum of 7, there is only one valid combination: 124. + +- 1 + 2 + 4 = 7 +- Any other combination that adds up to 7, e.g. 232, would violate the rule of not repeating digits within a cage. + +![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) + +## Example 2: Cage with several combinations + +In a 2-digit cage with a sum 10, there are 4 possible combinations: + +- 19 +- 28 +- 37 +- 46 + +![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) + +## Example 3: Cage with several combinations that is restricted + +In a 2-digit cage with a sum 10, where the column already contains a 1 and a 4, there are 2 possible combinations: + +- 28 +- 37 + +19 and 46 are not possible due to the 1 and 4 in the column according to standard Sudoku rules. + +![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) + +## Trying it yourself + +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). + +You can also find Killer Sudokus in varying difficulty in numerous newspapers, as well as Sudoku apps, books and websites. + +## Credit + +The screenshots above have been generated using [F-Puzzles.com](https://www.f-puzzles.com/), a Puzzle Setting Tool by Eric Fox. diff --git a/exercises/killer-sudoku-helper/metadata.toml b/exercises/killer-sudoku-helper/metadata.toml new file mode 100644 index 0000000000..63e5bda3c0 --- /dev/null +++ b/exercises/killer-sudoku-helper/metadata.toml @@ -0,0 +1,3 @@ +blurb = "Write a tool that makes it easier to solve Killer Sudokus" +source = "Created by Sascha Mann, Jeremy Walker, and BethanyG for the Julia track on Exercism." +source_url = "https://github.com/exercism/julia/pull/413" From 7681654952dd63b6978ce4f5e4095569c192fc1e Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Thu, 14 Apr 2022 14:28:26 +0200 Subject: [PATCH 2/4] Add alt texts Co-authored-by: Derk-Jan Karrenbeld --- exercises/killer-sudoku-helper/description.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/killer-sudoku-helper/description.md b/exercises/killer-sudoku-helper/description.md index 9a0fd1dc5f..cd7f7ffec4 100644 --- a/exercises/killer-sudoku-helper/description.md +++ b/exercises/killer-sudoku-helper/description.md @@ -20,7 +20,7 @@ In a 3-digit cage with a sum of 7, there is only one valid combination: 124. - 1 + 2 + 4 = 7 - Any other combination that adds up to 7, e.g. 232, would violate the rule of not repeating digits within a cage. -![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) +![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. 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) ## Example 2: Cage with several combinations @@ -31,7 +31,7 @@ In a 2-digit cage with a sum 10, there are 4 possible combinations: - 37 - 46 -![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) +![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) ## Example 3: Cage with several combinations that is restricted @@ -42,7 +42,7 @@ In a 2-digit cage with a sum 10, where the column already contains a 1 and a 4, 19 and 46 are not possible due to the 1 and 4 in the column according to standard Sudoku rules. -![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) +![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) ## Trying it yourself From f679e6162b405895d75095e9587c411038f6dc38 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Thu, 14 Apr 2022 14:51:19 +0200 Subject: [PATCH 3/4] Apply DJ's suggestion --- exercises/killer-sudoku-helper/description.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/killer-sudoku-helper/description.md b/exercises/killer-sudoku-helper/description.md index cd7f7ffec4..040636ad71 100644 --- a/exercises/killer-sudoku-helper/description.md +++ b/exercises/killer-sudoku-helper/description.md @@ -20,7 +20,7 @@ In a 3-digit cage with a sum of 7, there is only one valid combination: 124. - 1 + 2 + 4 = 7 - Any other combination that adds up to 7, e.g. 232, would violate the rule of not repeating digits within a cage. -![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. 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) +![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) ## Example 2: Cage with several combinations From eb2da98ead9787d299ca778f591b3f27bb614b6e Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Fri, 15 Apr 2022 10:38:42 +0200 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Peter Tseng --- .../killer-sudoku-helper/canonical-data.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/exercises/killer-sudoku-helper/canonical-data.json b/exercises/killer-sudoku-helper/canonical-data.json index 57270755d4..c1104908ae 100644 --- a/exercises/killer-sudoku-helper/canonical-data.json +++ b/exercises/killer-sudoku-helper/canonical-data.json @@ -24,7 +24,7 @@ "input": { "cage": { "sum": 2, - "size": 2, + "size": 1, "exclude": [] } }, @@ -37,7 +37,7 @@ "input": { "cage": { "sum": 3, - "size": 3, + "size": 1, "exclude": [] } }, @@ -50,7 +50,7 @@ "input": { "cage": { "sum": 4, - "size": 4, + "size": 1, "exclude": [] } }, @@ -63,7 +63,7 @@ "input": { "cage": { "sum": 5, - "size": 5, + "size": 1, "exclude": [] } }, @@ -76,7 +76,7 @@ "input": { "cage": { "sum": 6, - "size": 6, + "size": 1, "exclude": [] } }, @@ -89,7 +89,7 @@ "input": { "cage": { "sum": 7, - "size": 7, + "size": 1, "exclude": [] } }, @@ -102,7 +102,7 @@ "input": { "cage": { "sum": 8, - "size": 8, + "size": 1, "exclude": [] } }, @@ -115,7 +115,7 @@ "input": { "cage": { "sum": 9, - "size": 9, + "size": 1, "exclude": [] } },