Skip to content

Add 'piecing-it-together' 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

Merged
merged 31 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
901edbf
Add 'jigsaw-puzzle' exercise
atk Apr 7, 2025
58812e9
address pr comments
atk Apr 7, 2025
fb39822
address pr comments, 2nd part
atk Apr 8, 2025
fa94f00
input format for configurations, blurb improvements
atk Apr 8, 2025
47221ef
add missing expectation, instructions updates
atk Apr 8, 2025
81302e3
fix typo
atk Apr 8, 2025
1ada7f3
improve explanation
atk Apr 8, 2025
a3c5262
remove second part
atk Apr 9, 2025
62a5d73
fix json format
atk Apr 9, 2025
38ac4de
Update exercises/jigsaw-puzzle/introduction.md
atk Apr 9, 2025
8c79c78
fix: linter issues
atk Apr 11, 2025
4ae05cd
fix: uuids require uuid v4
atk Apr 11, 2025
ac36f29
improve wording
atk Apr 12, 2025
2e707c7
Update exercises/jigsaw-puzzle/instructions.md
atk Apr 13, 2025
d1bc3e6
Update exercises/jigsaw-puzzle/introduction.md
atk Apr 13, 2025
0616157
Update exercises/jigsaw-puzzle/canonical-data.json
atk Apr 13, 2025
007593d
Add more tests
atk Apr 15, 2025
824ac43
Fix typo in canonical data
atk Apr 15, 2025
eba955f
document aspect ratio choice
atk Apr 16, 2025
a1c5a69
Make comment more understandable
atk Apr 24, 2025
57eb31d
Add source_url
atk Apr 28, 2025
f12e79d
Clarify inside pieces
atk Apr 28, 2025
8e36f37
make introduction more whimsical
atk Apr 28, 2025
60e1c19
Rename to piecing-it-together
atk May 8, 2025
56a647d
add illustrated examples
atk May 10, 2025
14b4cf3
fix: linter errors
atk May 10, 2025
76730b8
fix: linter errors, 2nd part
atk May 10, 2025
5626758
final image urls
atk May 11, 2025
0b648ab
improve wording
atk May 12, 2025
7dc21ba
wording improvements
atk May 13, 2025
1fa797d
more improvements
atk May 13, 2025
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
127 changes: 127 additions & 0 deletions exercises/piecing-it-together/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"exercise": "piecing-it-together",
"comments": [
"For the aspect ratio, rational numbers can be used for languages without",
"IEEE-754 support. Their representation depends on the track (e.g., a tuple like",
"[numerator, denominator], a string like '3/4', or a custom rational type).",
"The represented fractions should be reduced to lowest terms 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"
}
}
]
}
41 changes: 41 additions & 0 deletions exercises/piecing-it-together/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Instructions

Given partial information about a jigsaw puzzle, add the missing pieces.

If the information is insufficient to complete the details, or if given parts are in contradiction, 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 (non-border) 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`

## Three examples

### Portrait

A portrait jigsaw puzzle with 6 pieces, all of which are border pieces and none are inside pieces. It has 3 rows and 2 columns. The aspect ratio is 1.5 (3/2).

![A 2 by 3 jigsaw puzzle](https://assets.exercism.org/images/exercises/piecing-it-together/jigsaw-puzzle-2x3.svg)

### Square

A square jigsaw puzzle with 9 pieces, all of which are border pieces except for the one in the center, which is an inside piece. It has 3 rows and 3 columns. The aspect ratio is 1 (3/3).

![A 3 by 3 jigsaw puzzle](https://assets.exercism.org/images/exercises/piecing-it-together/jigsaw-puzzle-3x3.svg)

### Landscape

A landscape jigsaw puzzle with 12 pieces, 10 of which are border pieces and 2 are inside pieces. It has 3 rows and 4 columns. The aspect ratio is 1.333333... (4/3).

![A 4 by 3 jigsaw puzzle](https://assets.exercism.org/images/exercises/piecing-it-together/jigsaw-puzzle-4x3.svg)
6 changes: 6 additions & 0 deletions exercises/piecing-it-together/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 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.
Even with your powers combined, it takes multiple hours to solve a single jigsaw puzzle with one thousand pieces — and then you still need to count the rows and columns and calculate the remaining numbers manually.
The even larger puzzles with thousands of pieces look quite daunting now.
"There has to be a better way!" you exclaim and sit down in front of your computer to solve the problem.
4 changes: 4 additions & 0 deletions exercises/piecing-it-together/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title = "Piecing It Together"
blurb = "Fill in missing jigsaw puzzle details from partial data"
source = "atk just started another 1000-pieces jigsaw puzzle when this idea hit him"
source_url = "https://github.com/exercism/problem-specifications/pull/2554"
Loading