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

Integers, Assemble!

$
0
0

Your task is to assemble the integers from 1 to N (given as input) into a rectangle of width W and height H (also given as input). Individual numbers may be rotated by any multiple of 90 degrees, but they must appear as contiguous blocks in the rectangle. That is, you cannot break one of the numbers into multiple digits and place the digits in the rectangle individually, neither can you bend three digits of a number around a corner. You could consider each number a brick from which you're building a wall.

Here is an example. Say your input is (N, W, H) = (12, 5, 3). One possible solution is:

186272190153114

For clarity, here are two copies of this grid, one with the one-digit numbers hidden and one with the two-digit numbers hidden:

1####    #86272##01    #19####11#    53##4

It's fine if the rectangle cannot be disassembled again in a unique way. For instance, in the above example, the 12 could also have been placed like this:

#####    1862721#01    ##9####11#    53##4

Rules

You may assume that N is positive and that W*H matches the number of digits in the integers from 1 to N inclusive, and that a tiling of the rectangle into the given numbers exists. I don't currently have a proof whether this is always possible, but I'd be interested in one if you do.

Output may either be a single linefeed-separated string or a list of strings (one for each line) or a list of lists of single-digit integers (one for each cell).

The results of your submission must be determinstic and you should be able to handle all test cases in less than a minute on reasonable desktop machine.

You may write a program or a function and use any of the our standard methods of receiving input and providing output.

You may use any programming language, but note that these loopholes are forbidden by default.

This is , so the shortest valid answer – measured in bytes– wins.

Test Cases

Except for the first one, none of these are unique. Each test case is N W H followed by a possible output. Make sure that your answer works when the rectangle is too narrow to write the larger numbers horizontally.

1 1 116 6 15361426 2 316253410 1 111089267315411 13 1123456789101127 9 5213112117192422581144136119082512671205263272183 21 21183116214112099785736182516114011998775635181116013911897765534180415913811796755433179115813711695745332178315713611594735231177115613511493725130176215513411392715029175115413311291704928174115313211190694827173115213111089684726172015113010988674625171915012910887664524170814912810786654423169714812710685644322168614712610584634221167514612510483624120166414512410382614019165314412310281603918164214312210180593817163114212110079583716200 41 12817111329171936611141055331189361111841365059292444881591541456296760990995366249189529721161671582389717813151113658811817414181845111101190101834237204330173311183517118361400354746118119727518430011171141874381132041861871718311415915921116264119142450141127110115944926268312193318451712511262922208516634470773609095637518194507611291431121128817413566319161275711110115400211199135110111699395517298807809272514160772766563270256736989353427730478118311405621148296417218591118562161856

Viewing all articles
Browse latest Browse all 35

Trending Articles



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