Skip to content

Commit 087e5e3

Browse files
atkErikSchierboomtasxatzial
authored
Add 'piecing-it-together' exercise (#2554)
* Add 'jigsaw-puzzle' exercise * address pr comments * address pr comments, 2nd part * input format for configurations, blurb improvements * add missing expectation, instructions updates * fix typo * improve explanation * remove second part * fix json format * Update exercises/jigsaw-puzzle/introduction.md Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com> * fix: linter issues * fix: uuids require uuid v4 * improve wording * Update exercises/jigsaw-puzzle/instructions.md Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update exercises/jigsaw-puzzle/introduction.md Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update exercises/jigsaw-puzzle/canonical-data.json Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Add more tests * Fix typo in canonical data Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * document aspect ratio choice * Make comment more understandable Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Add source_url Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com> * Clarify inside pieces Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com> * make introduction more whimsical * Rename to piecing-it-together * add illustrated examples * fix: linter errors * fix: linter errors, 2nd part * final image urls * improve wording * wording improvements * more improvements --------- Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com> Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
1 parent d703be6 commit 087e5e3

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"exercise": "piecing-it-together",
3+
"comments": [
4+
"For the aspect ratio, rational numbers can be used for languages without",
5+
"IEEE-754 support. Their representation depends on the track (e.g., a tuple like",
6+
"[numerator, denominator], a string like '3/4', or a custom rational type).",
7+
"The represented fractions should be reduced to lowest terms to avoid ambiguity."
8+
],
9+
"cases": [
10+
{
11+
"uuid": "ad626f23-09a2-4f5f-ba22-eec0671fa2a9",
12+
"description": "1000 pieces puzzle with 1.6 aspect ratio",
13+
"property": "jigsawData",
14+
"input": {
15+
"pieces": 1000,
16+
"aspectRatio": 1.6
17+
},
18+
"expected": {
19+
"pieces": 1000,
20+
"border": 126,
21+
"inside": 874,
22+
"rows": 25,
23+
"columns": 40,
24+
"aspectRatio": 1.6,
25+
"format": "landscape"
26+
}
27+
},
28+
{
29+
"uuid": "3e0c5919-3561-42f5-b9ed-26d70c20214e",
30+
"description": "square puzzle with 32 rows",
31+
"property": "jigsawData",
32+
"input": {
33+
"rows": 32,
34+
"format": "square"
35+
},
36+
"expected": {
37+
"pieces": 1024,
38+
"border": 124,
39+
"inside": 900,
40+
"rows": 32,
41+
"columns": 32,
42+
"aspectRatio": 1.0,
43+
"format": "square"
44+
}
45+
},
46+
{
47+
"uuid": "1126f160-b094-4dc2-bf37-13e36e394867",
48+
"description": "400 pieces square puzzle with only inside pieces and aspect ratio",
49+
"property": "jigsawData",
50+
"input": {
51+
"inside": 324,
52+
"aspectRatio": 1.0
53+
},
54+
"expected": {
55+
"pieces": 400,
56+
"border": 76,
57+
"inside": 324,
58+
"rows": 20,
59+
"columns": 20,
60+
"aspectRatio": 1.0,
61+
"format": "square"
62+
}
63+
},
64+
{
65+
"uuid": "a9743178-5642-4cc0-8fdb-00d6b031c3a0",
66+
"description": "1500 pieces landscape puzzle with 30 rows and 1.6 aspect ratio",
67+
"property": "jigsawData",
68+
"input": {
69+
"rows": 30,
70+
"aspectRatio": 1.6666666666666667
71+
},
72+
"expected": {
73+
"pieces": 1500,
74+
"border": 156,
75+
"inside": 1344,
76+
"rows": 30,
77+
"columns": 50,
78+
"aspectRatio": 1.6666666666666667,
79+
"format": "landscape"
80+
}
81+
},
82+
{
83+
"uuid": "f6378369-989c-497f-a6e2-f30b1fa76cba",
84+
"description": "300 pieces portrait puzzle with 70 border pieces",
85+
"property": "jigsawData",
86+
"input": {
87+
"pieces": 300,
88+
"border": 70,
89+
"format": "portrait"
90+
},
91+
"expected": {
92+
"pieces": 300,
93+
"border": 70,
94+
"inside": 230,
95+
"rows": 25,
96+
"columns": 12,
97+
"aspectRatio": 0.48,
98+
"format": "portrait"
99+
}
100+
},
101+
{
102+
"uuid": "f53f82ba-5663-4c7e-9e86-57fdbb3e53d2",
103+
"description": "puzzle with insufficient data",
104+
"property": "jigsawData",
105+
"input": {
106+
"pieces": 1500,
107+
"format": "landscape"
108+
},
109+
"expected": {
110+
"error": "Insufficient data"
111+
}
112+
},
113+
{
114+
"uuid": "a3d5c31a-cc74-44bf-b4fc-9e4d65f1ac1a",
115+
"description": "puzzle with contradictory data",
116+
"property": "jigsawData",
117+
"input": {
118+
"rows": 100,
119+
"columns": 1000,
120+
"format": "square"
121+
},
122+
"expected": {
123+
"error": "Contradictory data"
124+
}
125+
}
126+
]
127+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Instructions
2+
3+
Given partial information about a jigsaw puzzle, add the missing pieces.
4+
5+
If the information is insufficient to complete the details, or if given parts are in contradiction, the user should be notified.
6+
7+
The full information about the jigsaw puzzle contains the following parts:
8+
9+
- `pieces`: Total number of pieces
10+
- `border`: Number of border pieces
11+
- `inside`: Number of inside (non-border) pieces
12+
- `rows`: Number of rows
13+
- `columns`: Number of columns
14+
- `aspectRatio`: Aspect ratio of columns to rows
15+
- `format`: Puzzle format, which can be `portrait`, `square`, or `landscape`
16+
17+
For this exercise, you may assume square pieces, so that the format can be derived from the aspect ratio:
18+
19+
- If the aspect ratio is less than 1, it's `portrait`
20+
- If it is equal to 1, it's `square`
21+
- If it is greater than 1, it's `landscape`
22+
23+
## Three examples
24+
25+
### Portrait
26+
27+
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).
28+
29+
![A 2 by 3 jigsaw puzzle](https://assets.exercism.org/images/exercises/piecing-it-together/jigsaw-puzzle-2x3.svg)
30+
31+
### Square
32+
33+
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).
34+
35+
![A 3 by 3 jigsaw puzzle](https://assets.exercism.org/images/exercises/piecing-it-together/jigsaw-puzzle-3x3.svg)
36+
37+
### Landscape
38+
39+
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).
40+
41+
![A 4 by 3 jigsaw puzzle](https://assets.exercism.org/images/exercises/piecing-it-together/jigsaw-puzzle-4x3.svg)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Introduction
2+
3+
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.
4+
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.
5+
The even larger puzzles with thousands of pieces look quite daunting now.
6+
"There has to be a better way!" you exclaim and sit down in front of your computer to solve the problem.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
title = "Piecing It Together"
2+
blurb = "Fill in missing jigsaw puzzle details from partial data"
3+
source = "atk just started another 1000-pieces jigsaw puzzle when this idea hit him"
4+
source_url = "https://github.com/exercism/problem-specifications/pull/2554"

0 commit comments

Comments
 (0)