Skip to content

Add 'jigsaw-puzzle' exercise #2554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions exercises/jigsaw-puzzle/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"exercise": "jigsaw-puzzle",
"comments": [
"For the aspect ratio, rational numbers can be used for languages without IEEE-754 support",
"If rational numbers are used, they need to be reduced to the lowest term to avoid ambiguity"
],
"cases": [
{
"uuid": "ad626f23-09a2-4f5f-ba22-eec0671fa2a9",
"description": "1000 pieces puzzle with 1.6 aspect ratio",
"property": "jigsawData",
"input": {
"pieces": 1000,
"aspectRatio": 1.6
},
"expected": {
"pieces": 1000,
"border": 126,
"inside": 874,
"rows": 25,
"columns": 40,
"aspectRatio": 1.6,
"format": "landscape"
}
},
{
"uuid": "3e0c5919-3561-42f5-b9ed-26d70c20214e",
"description": "square puzzle with 32 rows",
"property": "jigsawData",
"input": {
"rows": 32,
"format": "square"
},
"expected": {
"pieces": 1024,
"border": 124,
"inside": 900,
"rows": 32,
"columns": 32,
"aspectRatio": 1.0,
"format": "square"
}
},
{
"uuid": "1126f160-b094-4dc2-bf37-13e36e394867",
"description": "400 pieces square puzzle with only inside pieces and aspect ratio",
"property": "jigsawData",
"input": {
"inside": 324,
"aspectRatio": 1.0
},
"expected": {
"pieces": 400,
"border": 76,
"inside": 324,
"rows": 20,
"columns": 20,
"aspectRatio": 1.0,
"format": "square"
}
},
{
"uuid": "a9743178-5642-4cc0-8fdb-00d6b031c3a0",
"description": "1500 pieces landscape puzzle with 30 rows and 1.6 aspect ratio",
"property": "jigsawData",
"input": {
"rows": 30,
"aspectRatio": 1.6666666666666667
},
"expected": {
"pieces": 1500,
"border": 156,
"inside": 1344,
"rows": 30,
"columns": 50,
"aspectRatio": 1.6666666666666667,
"format": "landscape"
}
},
{
"uuid": "f6378369-989c-497f-a6e2-f30b1fa76cba",
"description": "300 pieces portrait puzzle with 70 border pieces",
"property": "jigsawData",
"input": {
"pieces": 300,
"border": 70,
"format": "portrait"
},
"expected": {
"pieces": 300,
"border": 70,
"inside": 230,
"rows": 25,
"columns": 12,
"aspectRatio": 0.48,
"format": "portrait"
}
},
{
"uuid": "f53f82ba-5663-4c7e-9e86-57fdbb3e53d2",
"description": "puzzle with insufficient data",
"property": "jigsawData",
"input": {
"pieces": 1500,
"format": "landscape"
},
"expected": {
"error": "Insufficient data"
}
},
{
"uuid": "a3d5c31a-cc74-44bf-b4fc-9e4d65f1ac1a",
"description": "puzzle with contradictory data",
"property": "jigsawData",
"input": {
"rows": 100,
"columns": 1000,
"format": "square"
},
"expected": {
"error": "Contradictory data"
}
}
]
}
21 changes: 21 additions & 0 deletions exercises/jigsaw-puzzle/instructions.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file could be improved a bit by adding an example, ideally with some visual(s)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of visuals did you have in mind and how could I include them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That I'm not sure of, but we've had @habere-et-dispertire create some nice images.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Instructions

Given partial information about a jigsaw puzzle, complete the remaining details.

If the information is insufficient to complete the details, or if it contains contradictions, the user should be notified.

The full information about the jigsaw puzzle contains the following parts:

- `pieces`: Total number of pieces
- `border`: Number of border pieces
- `inside`: Number of inside pieces
- `rows`: Number of rows
- `columns`: Number of columns
- `aspectRatio`: Aspect ratio of columns to rows
- `format`: Puzzle format, which can be `portrait`, `square`, or `landscape`

For this exercise, you may assume square pieces, so that the format can be derived from the aspect ratio:

- If the aspect ratio is less than 1, it's `portrait`
- If it is equal to 1, it's `square`
- If it is greater than 1, it's `landscape`
4 changes: 4 additions & 0 deletions exercises/jigsaw-puzzle/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Introduction

Your best friend has started collecting jigsaw puzzles and wants to build a detailed catalog of their collection — recording information such as the total number of pieces, the number of rows and columns, the number of border and inside pieces, aspect ratio, and puzzle format.
After solving one of the puzzles to figure out these details, you're now helping fill in the gaps for others in the collection, even when some data is missing.
3 changes: 3 additions & 0 deletions exercises/jigsaw-puzzle/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title = "Jigsaw Puzzle"
blurb = "Fill in missing jigsaw puzzle details from partial data"
source = "atk just started another 1000-pieces jigsaw puzzle when this idea hit him"