26
\$\begingroup\$

Challenge

Given a positive integer \$N\$, repeat each of its digits \$d_1, d_2, d_3, \cdots, d_n\$ a number of times corresponding to its position in \$N\$. In other words, each digit \$d_k\$ should be repeated \$k\$ times (for each \$1\le k\le n\$, 1-indexed), thus creating the new number:

$$\overline{d_1d_2d_2d_3d_3d_3\cdots\underbrace{d_nd_nd_n\cdots d_n}_{n\text { times}}}$$

Then, write it down both horizontally and vertically and fill in the blanks with copies of the digit that corresponds to the greater index between the column index and the row index of the blank space. The final output should look like this:

$$\begin{bmatrix} \color{red}{d_1} \color{green}{d_2 d_2} \color{blue}{d_3 d_3 d_3} \cdots \\ \color{green}{d_2 d_2 d_2} \color{blue}{d_3 d_3 d_3} \cdots \\ \color{green}{d_2 d_2 d_2} \color{blue}{d_3 d_3 d_3} \cdots \\ \color{blue}{d_3 d_3 d_3 d_3 d_3 d_3} \cdots \\ \color{blue}{d_3 d_3 d_3 d_3 d_3 d_3} \cdots \\ \color{blue}{d_3 d_3 d_3 d_3 d_3 d_3} \cdots \\ \vdots \end{bmatrix}$$


Specs

You may take \$N\$ as an integer, a string, a list of digits or a list of characters representing the digits. The output can be a newline-separated string, a list of strings / integers or a list of lists of characters / digits, but please include a pretty-print version too, if possible. If the output is a newline-separated string, it is also acceptable to:

  • have leading / trailing whitespace, as long as the visual appearance of the output doesn't change
  • separate the columns using a consistent amount spaces or the rows with a consistent (non-zero) amount of newlines

You can take input and provide output through any standard method, while taking note that these loopholes are forbidden by default. This is , so try to complete the task in the least bytes you can manage in your language of choice.

Test cases

65:

655
555
555

---------------

203:

200333
000333
000333
333333
333333
333333

--------------

233:

233333
333333
333333
333333
333333
333333

---------------

5202:

5220002222
2220002222
2220002222
0000002222
0000002222
0000002222
2222222222
2222222222
2222222222
2222222222

---------------

12345:

122333444455555
222333444455555
222333444455555
333333444455555
333333444455555
333333444455555
444444444455555
444444444455555
444444444455555
444444444455555
555555555555555
555555555555555
555555555555555
555555555555555
555555555555555
\$\endgroup\$
3
  • \$\begingroup\$ Do we have the handle two of the same digit next to one another? \$\endgroup\$ Commented Jun 25, 2018 at 12:04
  • \$\begingroup\$ @DomHastings Yes, you have to handle them. Added a test case illustrating this. \$\endgroup\$
    – Mr. Xcoder
    Commented Jun 25, 2018 at 12:05
  • \$\begingroup\$ Related \$\endgroup\$ Commented Jun 25, 2018 at 13:57

32 Answers 32

1
2
0
\$\begingroup\$

Yabasic, 108 bytes

An anonymous function that takes input from STDIN and outputs to STDOUT

Input""s$
n=len(s$)
For y=1To n
For r=1To y
For x=1To n
For c=1To x?Mid$(s$,max(x,y),1);Next
Next
?Next
Next

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Uiua SBCS, 11 bytes

⊏⊞↥.▽+1.⇡⧻.

Try it!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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