Simulating bombs
The aim of this puzzle is to simulate the impact of the shock wave of bombs on a square grid. The grid initially contains cells labelled 0
along with several bombs of type A
, H
, or B
. Display the greatest intensity of shockwaves felt at each cell after the bombs explode.
The three bombs have different explosion patterns. Consider the following generic configuration, where the X
will be replaced by the different types of bombs. Note that for each bomb, the bomb's location is not replaced by a number.
000000000
000000000
000000000
000000000
0000X0000
000000000
000000000
000000000
000000000
For the A
-bomb:
000000000
011111110
012222210
012333210
0123A3210
012333210
012222210
011111110
000000000
For the H
-bomb:
000000000
055555550
055555550
055555550
0555H5550
055555550
055555550
055555550
000000000
For the B
-bomb:
000000000
000010000
000020000
000030000
0123B3210
000030000
000020000
000010000
000000000
Unlike the other bombs, the B
-bomb will not explode unless it is within the shockwave of another exploding bomb
Input & Output
- You are given an integer
n
, representing the grid size ofn*n
- You are then given the grid of
n*n
- You may take in the input as a list of
n
lines - Output the shock waves of all bombs
- You may output as a matrix/list/array
Test cases
1
H
->
H
15
000000000000000
A00A0000000000A
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
0000000A0000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
A000000000000AA
->
333332100001233
A33A3210000123A
333332100001233
222222100001222
111111100001111
000011111110000
000012222210000
000012333210000
0000123A3210000
000012333210000
000012222210000
111111111111111
222100000012222
332100000012333
A321000000123AA
18
000000000000000000
0AAAA00000000AAAA0
000000000000000000
000000000000000000
000000000000000000
000000000000000000
AA0000000000000000
000000000000000000
000000000000000000
000000000000000000
00000000000000A000
000000000000000000
000000000000000000
00000A000000000000
000000000000000000
000000000000000000
00000000000000000A
A00A000A0000A00000
->
333333210012333333
3AAAA32100123AAAA3
333333210012333333
222222210012222222
222211110011111111
333210000000000000
AA3210000000000000
333210000001111111
222210000001222221
111110000001233321
00111111100123A321
001222221001233321
001233321001222221
00123A321001111111
111233321111111222
222222222222222233
33333233322333223A
A33A323A3223A32233
18
H00000000000000000
000000000000000H00
000000000000000000
00000000H000000000
000000000000000000
000000000000000000
000000000000000000
000000HH0000000000
000000000000000000
000000000000000000
000000000000000H00
000000000000000000
000000000000000000
000000000000000000
HHH00000000H000000
000000000000000000
000000000000000000
000000000000000000
->
H55505555555555555
555505555555555H55
555505555555555555
55550555H555555555
000555555555555555
000555555555000000
000555555555000000
000555HH5550555555
000555555550555555
000555555550555555
000555555550555H55
555555005555555555
555555005555555555
555555005555555555
HHH55500555H555000
555555005555555000
555555005555555000
555555005555555000
22
000000000000000000000A
00000B0000000000000000
0000000000000000000000
0B0000000000000000000B
000000000000000000B000
0000000000000000000000
000000000000000000000B
0000000000000000000000
000000B00000000A000000
000000000000000000000B
0000000000000000000000
000000B000000000000000
000000000000000000000B
0000000000000000000000
000000000H000000000000
000000000000000000000B
0000000000000000000000
A000000000000000000000
A00000000000B000000000
A000000000000000000000
HHHH00000000000000A00H
00000000A0000000000000
->
000000000000000000123A
00000B0000000000001233
0000000000000000001223
0B0000000000000000123B
000000000000000000B003
0000001000001111111003
000000200000122222123B
0000003000001233321003
000123B32100123A321003
000000300000123332123B
0000003000001222221003
000123B555555111111003
000000555555500000123B
0000005555555000000003
111100555H555000000003
222100555555500000123B
3321005555555000000003
A555555555555001115555
A55555511111B001225555
A555555222210001235555
HHHH55533321000123A55H
55555553A3210001235555
Others
¤ The place may already have felt the effect of other bombs before the grid bombs exploded. In this case the number of the cell will be different from 0
as soon as the grid is given
¤ There are only three types of bomb: A
, B
, H
¤ There may be no explosion
Scoring
This is code-golf, you know the rules ;)
Credits
Credits to this puzzle