2
\$\begingroup\$

Back again, stealing another question from stackoverflow.

You are given a list of integers >= 0. Generate in order square 1-matrices where the side length is given by the list entry of the current index and fill the rest with 0s.

So given a list 2,4,1,3 print this to stdout:

1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1

Rules

  • Efficiency doesn't matter. (as long as it terminates on e.g. TIO)
  • Standard loopholes are forbidden.
  • In/Output has to adhere to the default I/O consensus.
  • This is code-golf. Shortest answer in bytes wins!
\$\endgroup\$
  • 5
    \$\begingroup\$ A nice question, but a duplicate. \$\endgroup\$ – xnor Oct 23 '19 at 7:08
  • \$\begingroup\$ Sorry, that one wouldn't pop up when I searched for duplicates. \$\endgroup\$ – jaaq Oct 23 '19 at 11:22

Browse other questions tagged or ask your own question.