8
Given the input tilesX
and tilesY
create a method that would make a rectangular ring from the tiles.
The function must order the tiles in a ring like this:
tilesX
andtilesY
are always positive integer values, cannot be 0tilesX
andtilesY
are not always equal, expect values like:2x5
,6x3
etc.- Checking for invalid input is not necessary
- You can use any way to display the tiles, including 2d arrays, ASCII art or printed text.
- There's no strict way how the input is passed as long as it's two integers.
- Cannot be a line, drawing a rectangle size of
tilesX
andtilesY
pixels is not valid - The shortest code wins
1Could you give examples of input/output ? – FliiFe – 2016-04-17T15:35:32.730
2Can we use a full program as well as a function? – Blue – 2016-04-17T15:36:37.640
@FliiFe Input is two integers ( cannot be negative or null ), output is a printed image like in the image attached. – Creative Magic – 2016-04-17T15:37:35.357
Can the output be a 2D array? – Doorknob – 2016-04-17T15:38:32.777
@muddyfish I would very much prefer the solution to be mathematical and not a part of some API. – Creative Magic – 2016-04-17T15:38:46.503
@Doorknob sure, that's totally valid – Creative Magic – 2016-04-17T15:39:12.490
You can use any way to display the tiles You should clarify this. Can it be ASCII art? Any characters? – Luis Mendo – 2016-04-17T15:41:00.753
@LuisMendo yes, you can use ASCII art or any characters if you want to display it in the output window/console. I'll update the question. – Creative Magic – 2016-04-17T15:42:01.253
Sorry for the bombardment, but some clarifying questions, part 1: 1) Is the expected output an image (e.g. JPG/PNG/displayed to screen) or ASCII-art? You seem to mention both in the comments, 2) Is the "4x4" or similar text part of the output? 3) Any rules on spacing between the tiles? – Sp3000 – 2016-04-17T15:47:47.677
@Sp3000 no rule how to display the image, it can be text ( but I thought Mathematica golfers might want to output an image and not text ). No rule on how to pass the input, so long as the input are two integers. No rule for spacing the tiles. Each tile can be viewed as a pixel. – Creative Magic – 2016-04-17T15:51:12.850
In that case I'd recommend giving example outputs for ASCII art as well so people know what's allowed (allowing both image and ASCII output's a bit weird, but your choice I guess). I'd also suggest removing mentions of "square" if the width/height are taken as input, since that might confuse people. – Sp3000 – 2016-04-17T15:53:45.580
Clarifications part two: 4) In the case of ASCII output, any rules on what characters are allowed to represent the tiles and the blank space in between? – Sp3000 – 2016-04-17T15:55:08.963
I also suggest that you allow either a function or a program, as usual on this site. – Luis Mendo – 2016-04-17T15:57:43.007
@Sp3000 absolutely any characters can be used to represent the tile. There's no space between the tiles in case of ASCII/text output, the tiles must be neighboring to each other. – Creative Magic – 2016-04-17T15:59:25.643
@CreativeMagic If the output is an array, can we use the language's default displaying of arrays, even if that means spaces between the numbers? (see my answer for example) – Luis Mendo – 2016-04-17T16:00:47.647
@LuisMendo it's allowed, but it's simply my own preference to have the logic of placing the tiles in the method, other than that it's pretty free. – Creative Magic – 2016-04-17T16:00:50.180
Related. Related. – Martin Ender – 2016-04-17T16:30:08.933
@CreativeMagic When you say "cannot be a line... drawing a rectangle size is not valid", do you mean that it cannot be a thin line? That is, if the "line" becomes a frame one tile thick (see my answer) is it valid? – Luis Mendo – 2016-04-17T21:11:01.577
@LuisMendo your answer is valid, I just wanted to prevent a hack that would use drawing API's of some languages for example drawRect( 0, 0, tilesX, tilesY ) – Creative Magic – 2016-04-18T00:54:03.830