Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 12 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,18 @@
],
"difficulty": 6
},
{
"slug": "piecing-it-together",
"name": "Piecing It Together",
"uuid": "be303729-ad8a-4f4c-a235-6828a6734f05",
"practices": [],
"prerequisites": [
"exceptions",
"for-loops",
"if-else-statements"
],
"difficulty": 6
},
{
"slug": "queen-attack",
"name": "Queen Attack",
Expand Down
41 changes: 41 additions & 0 deletions exercises/practice/piecing-it-together/.docs/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/practice/piecing-it-together/.docs/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.
19 changes: 19 additions & 0 deletions exercises/practice/piecing-it-together/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"zamora-carlos"
],
"files": {
"solution": [
"src/main/java/PiecingItTogether.java"
],
"test": [
"src/test/java/PiecingItTogetherTest.java"
],
"example": [
".meta/src/reference/java/PiecingItTogether.java"
]
},
"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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import java.util.Objects;
import java.util.Optional;

public class PartialJigsawInformation {
private Optional<Integer> pieces;
private Optional<Integer> border;
private Optional<Integer> inside;
private Optional<Integer> rows;
private Optional<Integer> columns;
private Optional<Double> aspectRatio;
private Optional<String> format;

public PartialJigsawInformation(Integer pieces, Integer border, Integer inside, Integer rows, Integer columns, Double aspectRatio, String format) {
this.pieces = Optional.ofNullable(pieces);
this.border = Optional.ofNullable(border);
this.inside = Optional.ofNullable(inside);
this.rows = Optional.ofNullable(rows);
this.columns = Optional.ofNullable(columns);
this.aspectRatio = Optional.ofNullable(aspectRatio);
this.format = Optional.ofNullable(format);
}

public Optional<Integer> getPieces() {
return pieces;
}

public Optional<Integer> getBorder() {
return border;
}

public Optional<Integer> getInside() {
return inside;
}

public Optional<Integer> getRows() {
return rows;
}

public Optional<Integer> getColumns() {
return columns;
}

public Optional<Double> getAspectRatio() {
return aspectRatio;
}

public Optional<String> getFormat() {
return format;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
PartialJigsawInformation that = (PartialJigsawInformation) o;
return Objects.equals(pieces, that.pieces) && Objects.equals(border, that.border) && Objects.equals(inside, that.inside) && Objects.equals(rows, that.rows) && Objects.equals(columns, that.columns) && Objects.equals(aspectRatio, that.aspectRatio) && Objects.equals(format, that.format);
}

@Override
public int hashCode() {
return Objects.hash(pieces, border, inside, rows, columns, aspectRatio, format);
}

@Override
public String toString() {
return "PartialJigsawInformation{" + "pieces=" + pieces + ", border=" + border + ", inside=" + inside + ", rows=" + rows + ", columns=" + columns + ", aspectRatio=" + aspectRatio + ", format=" + format + '}';
}
}
Loading