diff --git a/exercises/piecing-it-together/canonical-data.json b/exercises/piecing-it-together/canonical-data.json new file mode 100644 index 000000000..c1de180b2 --- /dev/null +++ b/exercises/piecing-it-together/canonical-data.json @@ -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" + } + } + ] +} diff --git a/exercises/piecing-it-together/instructions.md b/exercises/piecing-it-together/instructions.md new file mode 100644 index 000000000..c0c966592 --- /dev/null +++ b/exercises/piecing-it-together/instructions.md @@ -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) diff --git a/exercises/piecing-it-together/introduction.md b/exercises/piecing-it-together/introduction.md new file mode 100644 index 000000000..2fa20f6c5 --- /dev/null +++ b/exercises/piecing-it-together/introduction.md @@ -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. diff --git a/exercises/piecing-it-together/metadata.toml b/exercises/piecing-it-together/metadata.toml new file mode 100644 index 000000000..55f18e0cc --- /dev/null +++ b/exercises/piecing-it-together/metadata.toml @@ -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"