Skip to content

Commit 6d7e651

Browse files
committed
Add 'jigsaw-puzzle' exercise
1 parent 30931f4 commit 6d7e651

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"exercise": "jigsaw-puzzle",
3+
"comments": [
4+
"You need to take only a few bits of information and provide the rest",
5+
"Selecting a data format for the input and the output is important"
6+
],
7+
"cases": [
8+
{
9+
"uuid": "123e44cd-1388-11f0-96bc-145afc5ea279",
10+
"description": "1000 pieces puzzle with 1.6 aspect ratio",
11+
"property": "jigsawData",
12+
"input": {
13+
"pieces": 1000,
14+
"aspectRatio": 1.6
15+
},
16+
"expected": {
17+
"pieces": 1000,
18+
"border": 126,
19+
"inside": 874,
20+
"rows": 25,
21+
"columns": 40,
22+
"aspectRatio": 1.6,
23+
"format": "portrait"
24+
}
25+
},
26+
{
27+
"uuid": "1da97b91-1388-11f0-a658-145afc5ea279",
28+
"description": "square puzzle with 32 rows",
29+
"property": "jigsawData",
30+
"input": {
31+
"rows": 32,
32+
"format": "square"
33+
},
34+
"expected": {
35+
"pieces": 1024,
36+
"border": 124,
37+
"inside": 900,
38+
"rows": 32,
39+
"columns": 32,
40+
"aspectRatio": 1.0,
41+
"format": "square"
42+
}
43+
},
44+
{
45+
"uuid": "25e21469-1388-11f0-881d-145afc5ea279",
46+
"description": "300 pieces puzzle with 70 border pieces",
47+
"property": "jigsawData",
48+
"input": {
49+
"pieces": 300,
50+
"border": 70,
51+
"inside": 230,
52+
"rows": 25,
53+
"columns": 12,
54+
"aspectRatio": 0.48,
55+
"format": "portrait"
56+
}
57+
},
58+
{
59+
"uuid": "2d910864-1388-11f0-9a22-145afc5ea279",
60+
"description": "3d ball puzzle with 81 pieces",
61+
"property": "jigsawData",
62+
"input": {
63+
"border": 0,
64+
"inside": 82
65+
},
66+
"expected": {
67+
"pieces": 81,
68+
"border": 0,
69+
"inside": 81,
70+
"rows": 9,
71+
"columns": 9,
72+
"aspectRatio": 1.0,
73+
"format": "3d ball"
74+
}
75+
},
76+
{
77+
"uuid": "32d6bfe1-1388-11f0-b268-145afc5ea279",
78+
"description": "puzzle with insufficient data",
79+
"property": "jigsawData",
80+
"input": {
81+
"pieces": 1500,
82+
"format": "landscape"
83+
},
84+
"expected": {
85+
"error": "Insufficient data"
86+
}
87+
},
88+
{
89+
"uuid": "42b3f426-1388-11f0-ab04-145afc5ea279",
90+
"description": "500 pieces configurations",
91+
"property": "jigsawConfigurations",
92+
"input": 100,
93+
"expected": [
94+
{ "rows": 1, "columns": 100 },
95+
{ "rows": 2, "columns": 50 },
96+
{ "rows": 4, "columns": 25 },
97+
{ "rows": 5, "columns": 20 },
98+
{ "rows": 10, "columns": 10 },
99+
{ "rows": 20, "columns": 5 },
100+
{ "rows": 25, "columns": 4 },
101+
{ "rows": 50, "columns": 2 },
102+
{ "rows": 100, "columns": 1 }
103+
]
104+
},
105+
{
106+
"uuid": "4ad014ab-1388-11f0-8431-145afc5ea279",
107+
"description": "prime number of pieces",
108+
"property": "jigsawConfigurations",
109+
"input": 739,
110+
"expected": [
111+
{ "rows": 1, "columns": 739 },
112+
{ "rows": 739, "columns": 1 }
113+
]
114+
}
115+
]
116+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Task 1
2+
3+
Provide a function `jigsawData` that receives a part of the information and fills in the blanks. If the provided information is insufficient to calculate the rest, there should be an error "Insufficient information". The full information about the jigsaw puzzle contains
4+
5+
- `pieces`: Number of pieces
6+
- `border`: Number of border pieces
7+
- `inside`: Number of inside pieces
8+
- `rows`: Number of rows of pieces
9+
- `columns`: Number of columns of pieces
10+
- `aspecRatio`: Aspect ratio of columns / rows
11+
- `format`: Format of the puzzle: `"portrait" / "square" / "landscape" / "3d ball"`
12+
13+
For the rows and columns of a 3d ball puzzle, assume a square distribution.
14+
15+
### Task 2
16+
17+
Spoilt by the comfort of your helper, your friend now no longer wants to count border pieces, so they want another function that gives them a list of the possible even rows/columns configuration for a number of pieces, so they can estimate from the picture in the future.
18+
19+
Write a `jigsawConfigurations` function that takes the number of pieces and returns an array of the possible numbers of rows and columns.
20+
21+
Start with the lowest number of rows and work your way up from there. While a single-row jigsaw puzzle might be a strange novelty, it is theoretically possible, so you should include this case.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Your best friend started to collect puzzles. A catalogue the collection should contain as much information as possible. After solving one of the puzzles to count the rows, columns, amount of border and inside pieces, you are tasked to provide some helper functions.

exercises/jigsaw-puzzle/metadata.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title = "Puzzle Helper"
2+
blurb = "Calculate data about puzzles"
3+
source = "atk just started another 1000-pieces puzzle when this idea hit him"

0 commit comments

Comments
 (0)