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.
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 piecesborder: Number of border piecesinside: Number of inside (non-border) piecesrows: Number of rowscolumns: Number of columnsaspectRatio: Aspect ratio of columns to rowsformat: 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:
portrait
square
landscape
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 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 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).
Sign up to Exercism to learn and master WebAssembly with 87 exercises, and real human mentoring, all for free.