Quantcast
Viewing all articles
Browse latest Browse all 35

ASCII Exact Cover with Rectangles

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 consistingof the following form: axb,cxd,... where a,b,c, and d 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

000000

or

000000

1x3

000

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

574x2,3x2,3x2,5x2,5x1

Output 1

00001110000111223333322333332244444

Input 2

443x2,2x1,2x2,2x2

Output 2

0001000122332233

Input 3

2104x2,3x2,3x2

Output 3

00001112220000111222

Clarifications

  • The dimensions of the rectangles used to cover the region are interchangeable e.g. for axba could be the height or width same goes for b.
  • 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 so shortest answer in bytes wins.

Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>