4
0
Challenge
Given a rectangular area arrange a group of rectangles such that they cover the rectangular area entirely.
Input
An integer denoting the height.
An integer denoting the width.
The dimensions of the rectangles consisting of the following form:
axb,cxd,...
wherea,b,c,
andd
are integers - any reasonable format is acceptable.
Output
An exact cover of the rectangular area.
Rectangles used to cover the area are represented in the following way:
2x3
00
00
00
or
000
000
1x3
0
0
0
or
000
Each rectangle is represented using a character 0-9
where 0
is used for the first rectangle inputted 1
for the second and so on. The max number of rectangles given in input is therefore 10.
Test Cases
Input 1
5
7
4x2,3x2,3x2,5x2,5x1
Output 1
0000111
0000111
2233333
2233333
2244444
Input 2
4
4
3x2,2x1,2x2,2x2
Output 2
0001
0001
2233
2233
Input 3
2
10
4x2,3x2,3x2
Output 3
0000111222
0000111222
Clarifications
- The dimensions of the rectangles used to cover the region are interchangeable e.g. for
axb
a
could be the height or width same goes forb
. - If there are multiple solutions any of them is acceptable (just display 1).
- Assume all inputs are valid.
- You can have a full program or a function (inputs may be treated broadly as 3 separate arguments).
- Output to stdout (or something similar).
- This is code-golf so shortest answer in bytes wins.
How do you handle cases with no solution/invalid input? – Julian Lachniet – 2017-05-20T23:46:48.120
@JulianLachniet all inputs are assumed to be valid. I'll add this to post. – Bobas_Pett – 2017-05-20T23:48:43.987
@JonathanAllan edited in "Clarifications" not sure if that's sufficient, if not I can try again. – Bobas_Pett – 2017-05-21T00:27:23.890
@JonathanAllan I could paste in an edit if you have one. Sorry for the annoyance. – Bobas_Pett – 2017-05-21T00:44:58.587
1@JonathanAllan yeah that's great. Thanks – Bobas_Pett – 2017-05-21T00:50:55.847
Related – HyperNeutrino – 2017-05-21T02:08:40.033