33
\$\begingroup\$

Take a matrix of positive integers as input, and make it explode!


The way you explode a matrix is by simply adding zeros around every element, including the outside borders.

Input/output formats are optional as always!

Test cases:

1
-----
0 0 0
0 1 0
0 0 0
--------------

1 4
5 2
-----
0 0 0 0 0
0 1 0 4 0
0 0 0 0 0
0 5 0 2 0
0 0 0 0 0
--------------

1 4 7
-----
0 0 0 0 0 0 0
0 1 0 4 0 7 0
0 0 0 0 0 0 0
--------------

6
4
2
-----
0 0 0
0 6 0
0 0 0
0 4 0
0 0 0
0 2 0
0 0 0
\$\endgroup\$

31 Answers 31

0
\$\begingroup\$

Python 2, 92 bytes

def n(a):
	l,g='0 ',len(a[0])*2+1;print l*g
	for i in a:print l+' 0 '.join(i)+' 0';print l*g

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.