2 kyu
Assorted Rectangular Pieces Puzzle
60 of 95docgunthrop
Description:
You are given an assortment of rectangular pieces and a square board with holes in it. You need to arrange the pieces on the board so that all the pieces fill up the holes in the board with no overlap.
Input
Your function will receive two arguments:
board
: an array/list of lengthn
where each element is a string of lengthn
consisting of0
s and/or spaces. Each contiguous cluster of0
s represents a hole in the board.pieces
: an array/list where each element is in the form[h,w]
whereh
andw
represent the height and width of each piece, respectively.
Output
An array with the position of each piece to solve the puzzle. Each element should be an array in the form [x,y,z]
where:
x
andy
represents the piece's top-left corner position, as illustrated in the example belowz
represents the orientation of the piece -- normal or rotated90
degrees. If rotated,z
is1
, otherwise it's0
- Each piece corresponds to the element from
pieces
with the same index position
Test Example
Figure A
: initial state of the puzzle board.
Figure B
: one possible configuration. Note that the number in each rectangle indicates its index in the input array.

board = [
' ',
' 00000 ',
' 00000 ',
' 00000 00 ',
' 000 ',
' 00 000 ',
' 0000 00 ',
' 0000 00 ',
' 00 000 0 ',
' 000 0 ',
' 0 0 ',
'000 '
]
pieces = [[1,1], [1,1], [1,2], [1,2], [1,2], [1,3], [1,3], [1,4], [1,4], [2,2], [2,2], [2,3], [2,3], [2,5]]
solve_puzzle(board,pieces); # [[11,0,0],[11,1,0],[1,1,0],[3,9,0],[10,2,1],[1,3,0],[8,10,1],[4,7,1],[6,6,1],[4,8,0],[8,7,0],[5,3,1],[6,1,1],[2,1,0]]
Technical Constraints
- Each test will have one or more possible solutions
- Every piece must be used to solve the puzzle
- Every piece is a rectangle with height and width in the range:
12 >= x >= 1
- Number of pieces:
70 >= pieces >= 1
n
xn
board dimensions:24 >= n >= 4
- Full Test Suite:
15
fixed tests,60
random tests - Efficiency is necessary to pass
- JavaScript: prototypes have been frozen and
require
has been disabled
If you enjoyed this kata, be sure to check out my other katas.
Puzzles
Performance
Algorithms
Game Solvers
Similar Kata:
Stats:
Created | Feb 22, 2018 |
Published | Mar 2, 2018 |
Warriors Trained | 1377 |
Total Skips | 531 |
Total Code Submissions | 3377 |
Total Times Completed | 95 |
JavaScript Completions | 39 |
Python Completions | 60 |
Total Stars | 82 |
% of votes with a positive feedback rating | 98% of 22 |
Total "Very Satisfied" Votes | 21 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 1 kyu |
Highest Assessed Rank | 1 kyu |
Lowest Assessed Rank | 2 kyu |