9
1
Given positive integer n < 10
, create a 2 dimensional matrix where each location is filled with its x
and y
index (starting from the top left).
For example:
Input: 2
00 10
10 11
Input: 3
00 10 20
01 11 21
02 12 22
Once the grid is created, randomly fill each index. This can be with an 'x' or any other way to denote a spot has been filled.
You determine which location to fill by randomly generating indices to fill the matrix. You can only fill n^2 times so you cannot fill as many times as you want until the matrix is completely filled. At the end the matrix must be filled so you must do some work to make sure that you check the random numbers that you use to fill to make sure that spot is not already filled.
Refresh or print after each fill in order to show the progression of the filling iterations.
Example for filling:
Input: 2
00 10
01 11
00
is randomly chosen:
XX 10
01 11
01
is randomly chosen:
XX 10
XX 11
00
is randomly chosen, but since it's already been chosen a re-roll chooses 10
:
XX XX
XX 11
11
is randomly chosen:
XX XX
XX XX
Do not print out the random numbers as visually I should be able to see which index was selected. By this I mean do not print "11
is randomly chosen:". It is here for exploratory sake.
Since this is code-golf The shortest code wins.
Have fun and happy golfing!
I don't understand what is so complicated about the instructions which are very clear. "create a 2 dimensional matrix where each location is filled with it's xy index (starting from the top left)" (Not a printable string). "Refresh or print after each fill in order to show the progression of the filling iterations." must show the progression. Why be overly specific when it just narrows how creative users can be with their solutions? – jacksonecac – 2016-10-11T17:49:47.513
Is
n>= 10
possible ? (you have to start to know about the maximum length to properly fill in leading 0's then). The filling for that case is one index at a time, not 1 digit at a time, right ? – Ton Hospel – 2016-10-11T19:36:36.167@TimmyD I agree that this should have spent more time in the Sandbox simply because that is what the sandbox is for but for me the instructions are pretty clear about what is required. Not a bad challenge IMHO. – ElPedro – 2016-10-11T19:38:03.183
@TonHospel Good point. I will edit to ensure n < 10 – jacksonecac – 2016-10-12T11:10:51.650
What's the bonus? And "GUI and black squares" could use some clarification. – Rɪᴋᴇʀ – 2016-10-12T14:14:44.397
"Do not print out the random numbers as visually I should be able to see which index was selected." What does that mean? – Rɪᴋᴇʀ – 2016-10-12T14:15:44.220
@EasterlyIrk In my example I print out each iteration of the matrix being filled. I displayed the numbers that were randomly chosen for reference. They should not be outputted in your solution. i.i "00 is randomly chosen:" should not be displayed. – jacksonecac – 2016-10-12T14:24:25.760
That could use some clarification then. – Rɪᴋᴇʀ – 2016-10-12T15:09:40.753
1This looks much better. I would still take out the references to "The shortest code wins with a bonus if some GUI was used instead of ASCII". It's still undefined. – Morgan Thrapp – 2016-10-12T16:10:54.990
@carusocomputing nothing, should have been omitted. – jacksonecac – 2016-10-12T18:04:54.380
@DLosc lets stick with xy so that its more clear what each location is. – jacksonecac – 2016-10-12T18:59:18.150
Your very first input 2 example seems incorrect, since it contains
10
twice and no01
. – Kevin Cruijssen – 2016-10-13T08:09:40.863What do you mean by 'refresh' in "Refresh or print after each fill in order to show the progression of the filling iterations." – corvus_192 – 2016-10-13T20:03:40.163
@corvus_192 However you want to display the different iterations of the filling in the of grid. So if you fill in 1, 1. You would display the grid with 1,1 filled. Then if the next is 2, 3 then you would fill 2, 3 and display the new matrix with 1, 1 and 2, 3 filled. – jacksonecac – 2016-10-14T12:06:35.273