14
4
Minesweeper is a logic game found on most OS's. The goal of the game is to determine where the mines are on a grid, given numbers indicating the number of mines around that spot.
Given a grid size, and a set of mines, generate the Minesweeper grid for that set of mines.
Input: Two integers indicating the grid size, and an undefined number of integers indicating the mine positions. Positions will be given as (column position, row position), and the indexes will start at row 1.
Output: The Minesweeper grid. If there are no mines around a block, print an x
. For each new row, print a newline. Please output all mines as an asterisk *
. Do not leave any whitespace between the values in the row when printing.
Test Cases:
Input "5 5 1 3 3 5 2 4":
xxxxx
11xxx
*21xx
2*21x
12*1x
Input "3 4 3 1 1 4 2 3 3 2":
x2*
13*
2*2
*21
Shortest code wins.
Are we safe to assume all inputs will have an even number of args? i.e.
5 5 1
will never be passed? – Gaffi – 2012-06-26T17:17:29.977@Gaffi: Yep. The input will always be valid input. – beary605 – 2012-06-26T22:45:05.627
The spec currently leaves the reader to deduce from the examples that the positions use 1-based indexes and that row 1 is at the top. (Or is the latter, at least, negotiable?) – Peter Taylor – 2012-06-27T09:17:23.960
@PeterTaylor: Yep. I guess I should make it more obvious. – beary605 – 2012-06-27T14:18:27.903
If you're choosing your winner now, w0lf's Golfscript answer is 1 character shorter than mine. – Gareth – 2012-06-30T07:03:03.980
He, I didn't notice that. I guess I will fix that. Thank you for pointing that out! – beary605 – 2012-06-30T07:04:10.290
1No problem. I'm still determined to find a way to shave a couple of characters off and regain the lead though. :-) – Gareth – 2012-06-30T07:06:45.567
I came back to this question after a long time and noticed that Gareth's answer is the shortest one now, so I should be marked as the winner. – Cristian Lupascu – 2015-10-09T06:13:21.797