19
2
Challenge
Create the shortest program that meets the requirements
Requirements
The code must generate a 5x5 grid of 0s, like so:
00000 00000 00000 00000 00000
The code must accept an input (column, row, character). The grid must change accordingly:
Start:
00000 00000 00000 00000 00000
Input:
(2,5,*)
Output:
0*000 00000 00000 00000 00000
(Note: the bottom-left corner is position 1,1.)
The program must return an error message other than the grid if the row/column input is not 1,2,3,4, or 5. This can be any message of your choice (as long as it's not the grid), so
0
is an acceptable error-output.The program must work with all printable ASCII characters (of a US keyboard).
THE WINNER
The winner will be the person who has the shortest code and fulfills all requirements. If more than one answer works and has the same (shortest) length, the person who answered first will be the winner.
8The program must return an error message. What error message? Can the program return
0
for error and the grid for success? – Rod – 2016-11-29T12:26:58.417That is a great idea. By an error message I meant something that tells the user that their input was invalid, but your idea would work just fine. – Dave Jones – 2016-11-29T12:28:45.490
1Where is the origin on the matrix? does it need to be zero or one indexed? – george – 2016-11-29T12:30:09.967
The bottom most left corner is (1,1). – Dave Jones – 2016-11-29T12:34:40.113
3Welcome to PPCG, by the way. – Erik the Outgolfer – 2016-11-29T12:40:25.447
4he program must work with all characters on the US keyboard Why not just ASCII? I do not even know the characters of a US keyboard, and that doesn't add anything to the challenge – Luis Mendo – 2016-11-29T14:02:43.470
1@LuisMendo I think the US keyboard is ASCII, or is at least a subset. – Conor O'Brien – 2016-11-29T14:03:21.423
I will disregard the US keyboard requirement. – Dave Jones – 2016-11-29T14:52:01.603
The program must return an error message if the row/column input is greater than 5 I suppose we must also throw an error for values lower than 1. But could you please edit your question to clarify this point? – Arnauld – 2016-11-29T15:47:08.107
@DaveJones Wouldn't if the row/column input is not 1, 2, 3, 4, or 5 be better? – Adám – 2016-11-29T16:19:00.013
yes. Sorry for the confusion. – Dave Jones – 2016-11-29T16:37:00.933
Does it matter how we output the grid as long is it is correct and errors on bad input? – Kade – 2016-11-29T18:31:52.053
no, the method of output is arbitrary as long as it fulfills the specifications of the challenge – Dave Jones – 2016-11-29T21:32:07.450
@ConorO'Brien My keyboard has F1-F12 and arrow keys (whick generates multi character escape sequences) and Print Screen (which generates something that is NOT an ASCII character) - so it is a superset of ASCII. I think we have to disregard the US keyboard requirement - otherwise my program actually needs to detect that the Print Screen or Pause key has been pressed and then which character should it stick in the grid? – Jerry Jeremiah – 2016-11-29T22:55:49.900
@JerryJeremiah but those aren't characters on the US keyboard. – Conor O'Brien – 2016-11-29T23:18:02.663
Wow, Turtlèd is going to have a good time here... – Destructible Lemon – 2016-11-29T23:25:23.363
As I said above, if you need to, you can disregard the US keyboard requirement as long as it works for all ascii characters – Dave Jones – 2016-11-30T02:13:53.703
Question says 'the code must generate a 5x5 grid of 0s', does that mean we need to output both the starting grid and the altered grid, or only the final grid? – steenbergh – 2016-11-30T13:29:17.917
You only need to output the final grid. – Dave Jones – 2016-12-01T12:37:23.157
-1 Because of the cumbersome I/O format.
– Esolanging Fruit – 2017-05-21T19:24:53.413