-
-
Notifications
You must be signed in to change notification settings - Fork 735
Add piecing it together practice exercise #2961
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
kahgoh
merged 11 commits into
exercism:main
from
zamora-carlos:add-piecing-it-together-practice-exercise
Jun 27, 2025
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
82737ae
Set up scaffold for practice exercise: Piecing It Together
zamora-carlos 4efdb7f
Implement PartialJigsawInformation helper class
zamora-carlos 44292bc
Add unit tests for PiecingItTogether exercise
zamora-carlos d8fb729
Implement reference solution for PiecingItTogether exercise
zamora-carlos bc92ec4
Add stub file for PiecingItTogether exercise
zamora-carlos 2c82a8e
Add Gradle wrapper and update editor config for piecing-it-together e…
zamora-carlos fb6d7eb
Refactor PartialJigsawInformation to JigsawInfo with builder pattern …
zamora-carlos eec11ac
Make getCompleteInformation static and improve naming of helper metho…
zamora-carlos 965396c
Simplify reference solution for piecing-it-together practice exercise
zamora-carlos 7d3aaa7
Refactor JigsawInfo builder to use Optionals and fix piecing-it-toget…
zamora-carlos bdd7ba9
Replace getFirst() with get(0) to fix incompatibility with JDK 17 in …
zamora-carlos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
exercises/practice/piecing-it-together/.docs/instructions.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
|
||
 | ||
|
||
### 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). | ||
|
||
 | ||
|
||
### 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). | ||
|
||
 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
67 changes: 67 additions & 0 deletions
67
...cises/practice/piecing-it-together/.meta/src/reference/java/PartialJigsawInformation.java
zamora-carlos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
zamora-carlos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
public class PartialJigsawInformation { | ||
private Optional<Integer> pieces; | ||
zamora-carlos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
private Optional<Integer> border; | ||
private Optional<Integer> inside; | ||
private Optional<Integer> rows; | ||
private Optional<Integer> columns; | ||
private Optional<Double> aspectRatio; | ||
zamora-carlos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
private Optional<String> format; | ||
|
||
public PartialJigsawInformation(Integer pieces, Integer border, Integer inside, Integer rows, Integer columns, Double aspectRatio, String format) { | ||
zamora-carlos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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 + '}'; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.