1
I'm retiling my kitchen with different coloured tiles. In fact, it's going to have at least 2 colours - and 26 colours as a maximum.
But, I'm fussy. I want this wall to look random, but sometimes random isn't random enough.
So, when I lay out my tiles, I don't want to have any the same colour next to each other in the 4 Cartesian directions. Diagonally adjacent is (of course) fine.
Acceptable:
┌───┐
│ A │
└───┘
┌───┬───┬───┐
│ A │ B │ A │
├───┼───┼───┤
│ B │ A │ B │
└───┴───┴───┘
┌───┬───┬───┐
│ A │ B │ C │
├───┼───┼───┤
│ C │ A │ B │
└───┴───┴───┘
Unacceptable:
┌───┬───┬───┐
│ A │ B │ A │
├───┼───┼───┤
│ A │ A │ B │
└───┴───┴───┘
┌───┬───┬───┐
│ A │ C │ C │
├───┼───┼───┤
│ C │ A │ B │
└───┴───┴───┘
Given input in the form A B N
where A
is the width, B
is the height and N
is the number of colours - an integer from 2 to 26 - you need to output a grid like so:
Input:
5 6 4
Example output:
A B C D A
B A D A C
A D C D A
B C B A B
D A D C A
B C A D C
The input will be given as a) 3 arguments to a function or b) as 3 separate input statements or b) as A B N
. Input will always be valid.
All colours have to be used and all valid tilings have to have a non-zero probability of being generated.
This is code-golf so the shortest code wins.
14... come on, you're familiar with the SE network; you should know better than to delete and repost questions. – Doorknob – 2015-11-15T15:17:49.580
2
You deleted and then reposted this question (and you should know full well that's highly frowned upon on SE...).
– Doorknob – 2015-11-15T15:20:44.7671
There were no answers on the original question. If you want to prevent answers while you're working on a question, use the Sandbox.
– Doorknob – 2015-11-15T15:22:01.8504You know you can undelete questions, right? (It's also recommended that you use the Sandbox anyway, even if you think there are no issues with your question, because there could still be (this question being a case in point).) – Doorknob – 2015-11-15T15:24:57.670
Let us continue this discussion in chat.
– Tim – 2015-11-15T15:25:06.480@Tim You can undelete and then edit quickly. Just paste this challenge over the old one. – Calvin's Hobbies – 2015-11-15T15:33:13.307
@Calvin'sHobbies should I do that now it's been reposted? – Tim – 2015-11-15T15:33:52.717
Does each row have to be printed space-separated? – Sp3000 – 2015-11-15T17:12:13.023
@Sp3000 yes it does. – Tim – 2015-11-15T17:12:34.060
What's the minimum for the width/height? Are they at least 2? – Reto Koradi – 2015-11-15T17:14:53.983
1@RetoKoradi one of them is at least two, and the min is 1. – Tim – 2015-11-15T17:15:47.423
Should the output be formatted exactly as in the example, i.e., using the first N uppercase letters, with spaces in rows and newlines between columns? – Dennis – 2015-11-15T17:37:42.643
@Dennis Space and newlines yes. No, the arrangment should not be fixed with
A B C D ... Z
. – Tim – 2015-11-15T17:41:27.107