Quantcast
Channel: Active questions tagged tiling - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 35

Arranging arbitrary shapes to fill a rectangular space

$
0
0

A while ago, I posted a challenge asking to determine whether or not it's possible to arrange arbitrary rectangles to fill a rectangular space, here. That got answers, so clearly it was too easy. (Just kidding, it was fairly challenging, congrats to the answerers :D)

Challenge

Given a bunch of arbitrary shapes (consisting of 1x1 square tiles) (up to 100 with a combined area of at most 1000), can you arrange them to fill a rectangular space, without rotations or reflections?

A shape is valid as input if it has at least 1 tile and all tiles are connected to each other by edges. For example:

Valid:

XXXX XXXX

Invalid:

XXXX XX

The shapes will be represented in input by using a non-whitespace character X, spaces, and newlines. Individual shapes will be separated by two newlines (i.e. split on \n\n). You can choose to use LF, CR, or CRLF as a newline. Alternatively, you can choose to use LF or CR as a single newline and CRLF as a double-newline for separating shapes. Please specify in your answer what you choose.

For example, this would be the input format for a 2x2 square and a 3x3 "donut":

XXXXXXXX XXXX(Optional trailing newline or double-newline)

The output should be either any truthy value or a consistent falsy value (but not an error). For example, you may output the valid arrangement if one exists or false, but you cannot error if there is no valid arrangement, neither can you output different values for having no valid arrangement.

Test Cases

Test Case 1

XXXXX  XXX XXXXTRUE

Valid Arrangement:

XXXXXYYXXXYX

Test Case 2

XXXXXXXFALSE

Test Case 3

XXXXXXX X  XX XXXXXXXXTRUE

Valid Arrangement:

XXXXXXXYXZZXXYXXXA

Test Case 4

XXX XXXXXXXXXTRUE

Valid Arrangement:

XXYZXYYZAAAZ

Notes

  • Each shape must be used exactly once in the arrangement
  • Shapes may not be rotated or reflected
  • The input can contain multiple identical shapes; in this case, each of those still needs to be used exactly once; that is, if two 5x3 rectangles are given in the input, two 5x3 rectangles must appear in the arrangement

Viewing all articles
Browse latest Browse all 35

Trending Articles



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