Let's design a digit mosaic

25

3

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

Mr. Xcoder

Posted 2018-06-23T07:34:50.547

Reputation: 39 774

Do we have the handle two of the same digit next to one another? – Dom Hastings – 2018-06-25T12:04:54.100

@DomHastings Yes, you have to handle them. Added a test case illustrating this. – Mr. Xcoder – 2018-06-25T12:05:41.543

Related – Magic Octopus Urn – 2018-06-25T13:57:49.293

Answers

9

JavaScript (ES7), 70 bytes

Takes input as a string. Returns a string with a trailing linefeed.

s=>(g=x=>(c=s[(x>y?x:y)**.5-1>>1])?c+g(x+8):x>y?`
`+g(1,y+=8):'')(y=1)

Try it online!

How?

Method

We build the output character by character by walking through a square matrix and converting each cell into an index \$i_{x,y}\$ into the input string.

Coordinates to string index

The upper bound \$u_{n}\$ of the \$n^{th}\$ digit area (0-indexed) along each axis is given by A000096:

$$u_{n} = \frac{n(n+3)}{2}$$ $$u_{0}=0,u_{1}=2,u_{2}=5,u_{3}=9,u_{4}=14,u_{5}=20,\dots$$

Given an integer \$k\$, we can find out in which area \$n=\lfloor{x}\rfloor+1\$ it is located by solving:

$$x²+3x-2k=0$$

Leading to:

$$x = \frac{\sqrt{1+8k}-3}{2}$$ $$n = \left\lfloor\frac{\sqrt{1+8k}-3}{2}\right\rfloor+1=\left\lfloor\frac{\sqrt{1+8k}-1}{2}\right\rfloor$$

For each cell \$(x, y)\$, we define:

$$v_{x,y} = \max(1+8x,1+8y)$$

These values \$v_{x,y}\$ are converted into indices \$i_{x,y}\$ into the input string by doing:

$$i_{x,y} = \left\lfloor\frac{\sqrt{v_{x,y}}-1}{2}\right\rfloor$$

 v(x,y) |  0  1  2  3  4  5  6  7  8  9        i(x,y) |  0  1  2  3  4  5  6  7  8  9
--------+-------------------------------      --------+-------------------------------
    0   |  1  9 17 25 33 41 49 57 65 73           0   |  0  1  1  2  2  2  3  3  3  3
    1   |  9  9 17 25 33 41 49 57 65 73           1   |  1  1  1  2  2  2  3  3  3  3
    2   | 17 17 17 25 33 41 49 57 65 73           2   |  1  1  1  2  2  2  3  3  3  3
    3   | 25 25 25 25 33 41 49 57 65 73           3   |  2  2  2  2  2  2  3  3  3  3
    4   | 33 33 33 33 33 41 49 57 65 73   -->     4   |  2  2  2  2  2  2  3  3  3  3
    5   | 41 41 41 41 41 41 49 57 65 73           5   |  2  2  2  2  2  2  3  3  3  3
    6   | 49 49 49 49 49 49 49 57 65 73           6   |  3  3  3  3  3  3  3  3  3  3
    7   | 57 57 57 57 57 57 57 57 65 73           7   |  3  3  3  3  3  3  3  3  3  3
    8   | 65 65 65 65 65 65 65 65 65 73           8   |  3  3  3  3  3  3  3  3  3  3
    9   | 73 73 73 73 73 73 73 73 73 73           9   |  3  3  3  3  3  3  3  3  3  3

Halting conditions

We know that we've reached:

  • the right boundary of the matrix when the character at \$i_{x,y}\$ does not exist and we have \$x > y\$

  • the bottom boundary of the matrix when the character does not exist and we have \$x \le y\$

Arnauld

Posted 2018-06-23T07:34:50.547

Reputation: 111 334

7

J, 16 15 bytes

-1 byte thanks to FrownyFrog!

{~#\<:@>./~@##\

Try it online!

Takes N as a string.

Explanation of th initial solution:

              #\   finds the length of the successive prefixes of the input (1 2 3...)
            #~     copies each digit as many times (1 2 2 3 3 3...)  
       >./~@       and creates a table of the max of the row/col numbers
  [:<:@            then subtract 1 from each element (for indexing)
{~                 select the corresponding digit from the input

Test session with input 203:

   #\ '203'
1 2 3

   #~#\ '203'
1 2 2 3 3 3

   >./~@#~#\ '203'
1 2 2 3 3 3
2 2 2 3 3 3
2 2 2 3 3 3
3 3 3 3 3 3
3 3 3 3 3 3
3 3 3 3 3 3

   <:@>./~@#~#\ '203'
0 1 1 2 2 2
1 1 1 2 2 2
1 1 1 2 2 2
2 2 2 2 2 2
2 2 2 2 2 2
2 2 2 2 2 2

   ({~[:<:@>./~@#~#\) '203'
200333
000333
000333
333333
333333
333333

Galen Ivanov

Posted 2018-06-23T07:34:50.547

Reputation: 13 815

1Hah, apart from the placement of the ), your APL answer is the same as the would-have-been mine. – Erik the Outgolfer – 2018-06-23T09:13:26.737

I really don't know J at all, but [:<:@ seems quite costly. Could you instead prepend something to the list you are indexing into to account for the 1-indexing (e.g. prepend a 0 in order to move each necessary element 1 position to the right)? – Mr. Xcoder – 2018-06-23T10:32:35.450

@Mr.Xcoder I was thinking about that. I'll try it to see if it would save some bytes. – Galen Ivanov – 2018-06-23T11:24:40.137

@EriktheOutgolfer {⍵[∘.⌈⍨(/⍨)⍳⍴⍵]} ? – Galen Ivanov – 2018-06-23T11:31:01.890

@GalenIvanov Yes, that. – Erik the Outgolfer – 2018-06-23T11:58:07.020

Save 1 byte: {~#\<:@>./~@##\ – FrownyFrog – 2018-06-24T11:49:21.313

@Mr.Xcoder the [: is not really part of it, it’s just <:@. Can’t think of anything shorter. – FrownyFrog – 2018-06-24T12:10:01.027

6

Haskell, 60 59 58 bytes

f x|s<-do(n,_)<-zip[0..]x;n<$[0..n]=[(x!!).max a<$>s|a<-s]

Try it online!


Point-free version (68 bytes)

(map=<<(.((snd.).max)).flip map).((\t@(n,c)->t<$[1..n])=<<).zip[1..]

Try it online!

Laikoni

Posted 2018-06-23T07:34:50.547

Reputation: 23 676

6

R, 59 bytes

function(a){m=outer(x<-rep(g<-seq(a),g),x,pmax);m[]=a[m];m}

Try it online!

  • I noticed that taking a vector of digits is acceptable, and this allowed me to save 21 bytes :)
  • -2 bytes thanks to @Giuseppe suggestion to accept only character vector
  • -2 bytes assigning in arguments definition

digEmAll

Posted 2018-06-23T07:34:50.547

Reputation: 4 599

1You could take a as a vector of characters, allowing you to set g=seq(a) directly. – Giuseppe – 2018-06-23T12:25:14.077

@Giuseppe: that's right! – digEmAll – 2018-06-23T12:26:13.403

6

Python 2, 71 bytes

i=j=0;r=''
for x in input():i+=1;r+=x*i
for c in r:print j*c+r[j:];j+=1

Try it online!

First generates the first row r, then iterates over r to print each line.

xnor

Posted 2018-06-23T07:34:50.547

Reputation: 115 687

5

Jelly, 7 bytes

Jx`»þ`ị

Try it online!

Clarified output.

Erik the Outgolfer

Posted 2018-06-23T07:34:50.547

Reputation: 38 134

5

05AB1E, 14 11 10 bytes

Saved 1 byte thanks to Magic Octopus Urn / Adnan

ƶJDv¬N×?=¦

Try it online!

Explanation

ƶ            # repeat each element its index (1-based) times 
 J           # join to string
  Dv         # for N in [0 ... len(string)-1] do
    ¬N×      # push the head repeated N times
       ?     # print without newline
        =    # print the rest of the string without popping
         ¦   # remove the head

Emigna

Posted 2018-06-23T07:34:50.547

Reputation: 50 798

1Try it online! = 10 – Magic Octopus Urn – 2018-06-25T13:16:20.487

1

No credit to me though, credit is Adnans: https://codegolf.stackexchange.com/a/87074/59376

– Magic Octopus Urn – 2018-06-25T13:16:38.297

@MagicOctopusUrn: Ah, that's brilliant! Thanks to both of you ;) – Emigna – 2018-06-25T13:52:14.813

4

APL (Dyalog Classic), 16 bytes

{⍵[∘.⌈⍨(/⍨⍳⍴⍵)]}

I'm separating this solution from the post with my J answer, as suggested by Jo King

Try it online!

Galen Ivanov

Posted 2018-06-23T07:34:50.547

Reputation: 13 815

3

Python 2, 74 bytes

i=1;a=[]
for c in input():exec"a=zip(*a+[c*-~len(a)]);"*i;i+=2+i%2
print a

Try it online!

Lynn

Posted 2018-06-23T07:34:50.547

Reputation: 55 648

3

Excel VBA, 95 bytes

An anonymous VBE immediate window funtion that takes input from [A1] and outputs to the console

n=[len(A1)]:For y=1To n:For l=1To y:?:For x=1To n:?String(x,Mid([A1],IIf(x>y,x,y)));:Next x,l,y

Ungolfed and commented

n=[len(A1)]                         ''  Get Length
For y=1To n                         ''  Iterate down input
For l=1To y                         ''  Iterate down repeat lines
?                                   ''  Print Newline
For x=1To n                         ''  Iterate accross input
?String(x,Mid([A1],IIf(x>y,x,y)));  ''  Print x of the `max(x,y)`th digit in input
Next x,r,y                          ''  Loop, Loop, Loop

Taylor Scott

Posted 2018-06-23T07:34:50.547

Reputation: 6 709

2

MATL, 15 12 bytes

tftY"t!2$X>)

Try it online!

I suspect this can be shortened, but it's not so bad...

          % implicit input, '230'
t         % duplicate input. Stack: ['230','230']
f         % indices of nonzero values. Stack: ['230',[1,2,3]]
t         % duplicate. Stack: ['230',[1,2,3],[1,2,3]]
Y"        % run-length decoding. Stack: ['230',[1,2,2,3,3,3]]
t         % duplicate. Stack: ['230',[1,2,2,3,3,3],[1,2,2,3,3,3]]
!         % transpose. Stack: ['230',[1,2,2,3,3,3],[1;2;2;3;3;3]]
2$X>      % elementwise maximum of 2 inputs, with broadcast.
          % Stack:
          % ['230',
          % [1, 2, 2, 3, 3, 3;
          %  2, 2, 2, 3, 3, 3;
          %  2, 2, 2, 3, 3, 3;
          %  3, 3, 3, 3, 3, 3;
          %  3, 3, 3, 3, 3, 3;
          %  3, 3, 3, 3, 3, 3]]
 )        % index into G
          % implicit end, display stack contents

Giuseppe

Posted 2018-06-23T07:34:50.547

Reputation: 21 077

2

Add++, 35 bytes

L,bLRdBcB]£X¦Ω+d‽b>1€Ω_A€Ω:AbLR¦+$T

Try it online!

How it works

We take input as a list of digits, while prevents us from a) having to cast to digits with BD, and also from having to save the digits, which would take two bytes.

First, we generate a range from [1 ... len(input)] with bLR, then we repeat each element \$n\$ in the range \$n\$ times. As automatic vectorisation doesn't exist in Add++, we zip it with itself, dBcB], to create a list of pairs \$[[1, 1], [2, 2] ... [n, n]]\$. We then apply starmap, coupled with repetition over the pairs: £X before concatenating them into one flat array (¦Ω+).

Next, we duplicate this array and table it by maximum, d‽b>. I.e. each element in the array is paired with each other element from the second array and the dyadic maximum command is run over the pair. For an example input of [6 5], this creates the array [1 2 2 2 2 2 2 2 2], which is a flattened version of the mosaic, as the indexes for the array. Unfortunately, Add++ uses 0-indexed arrays, so we need to decrement each element: 1€Ω_.

Then, we index into the input list, by pushing the input again (A), which again saves bytes by taking input as a list. Index into the list with €Ω: before chopping the array into the appropriately lengthed pieces. If the number of digits in the input is denoted by \$x\$, then the piece size is

$$\frac{x(x - 1)}{2}$$

or the \$x^{th}\$ triangular number. We generate that by pushing the input's length, calculating the range from 1 to that value, then taking the sum with AbLR¦+. Now, the stack, for an input of [6 5], looks like [[6 5 5 5 5 5 5 5 5] 3]. T chops the array into pieces of size \$n\$, but the arguments are currently in the wrong order, so we swap them with $ before chopping and returning with T.

user81291

Posted 2018-06-23T07:34:50.547

Reputation:

1

Python 2, 76 73 bytes

-3 bytes thanks to Lynn.

l=0;m=[]
for k in input():l+=1;m=[r+l*k for r in m]+l*[l*-~l/2*k]
print m

Try it online!

ovs

Posted 2018-06-23T07:34:50.547

Reputation: 21 408

1

Charcoal, 17 bytes

F⮌…LθUO⊕⊘×ι⁺³ι§θι

Try it online! Explanation:

F⮌…Lθ

Loop over the indices of the characters in reverse order.

⊕⊘×ι⁺³ι

Calculate the size of the square.

UO...§θι

Draw the square using the current character.

Neil

Posted 2018-06-23T07:34:50.547

Reputation: 95 035

1

Canvas, 12 bytes

ø╶{;l└²+:*;n

Try it here!

dzaima

Posted 2018-06-23T07:34:50.547

Reputation: 19 048

1

Charcoal, 14 bytes

E⭆θ×⊕κι×⊕κι‖O↗

Try it online!

How?

E⭆θ×⊕κι×⊕κι‖O↗ - implicitly print the result of...
E                - map:
  ⭆              -   over: string map:       
    θ             -     over: first input
     ×            -     using: repeat
        ι         -       what: ι (loop value)
      ⊕κ          -       by: incremented κ (loop counter)
         ×        -   using: repeat
            ι     -     what: ι (loop value)
          ⊕κ      -     by: incremented κ (loop counter)
             ‖O  - Reflect with overlap:
                ↗ -   direction: up-right

...can this method be golfed?

Jonathan Allan

Posted 2018-06-23T07:34:50.547

Reputation: 67 804

"...can this method be golfed?" Even Neil's solution is longer, so I don't see any hope here. :P – Erik the Outgolfer – 2018-06-23T15:07:40.350

×⊕κι twice though. – Jonathan Allan – 2018-06-23T15:11:28.003

The thing is, it's not easy to assign that to a variable, since the values of ι and κ change at every iteration of the Each loop. – Erik the Outgolfer – 2018-06-23T15:36:01.153

It needs to be a function but I don't know if it's even possible. – Jonathan Allan – 2018-06-23T15:40:56.500

The question to ask is if it's possible in 3 (or 5, depending on how the function is defined) bytes or less. ;) (The obvious answer is, of course, not.) – Erik the Outgolfer – 2018-06-23T16:26:53.400

1

QBasic 1.1, 127 bytes

INPUT S$
FOR X=1TO LEN(S$)
K=K+X
R$=R$+STRING$(X,MID$(S$,X,1))
NEXT
FOR C=1TO K
?STRING$(C-1,MID$(R$,C,1))RIGHT$(R$,K-C+1)
NEXT

-4 thanks to DLosc.

Uses a modified version of xnor's Python 2 algorithm.

Input is an unquoted string. Output is \n-separated without extra spaces or \ns.

Erik the Outgolfer

Posted 2018-06-23T07:34:50.547

Reputation: 38 134

1

Stax, 12 bytes

ü°√¿«│⌠º₧@\τ

Run and debug it

Using this algorithm.

Explanation:

c%R:BXm]i*xit+ Full program, implicit input
c%             Length of input
  R            1-based range
   :B          Repeat each element according to the range ("123" -> "122333")
     X         Save to X register
      m        Map:
       ]         Character -> string
        i*       Repeat by iteration index
          xit    Trim first <iteration index> elements from X
             +   Concatenate
                 Implicit output with newline

Stax, 20 19 18 16 bytes

ù↔‼i,ÑΓæ☺=╘‼æ↕4╝

Run and debug it

Explanation:

c%R:BX%mYx%{y|Mvx@m Full program, implicit input
c%                  Length of input
  R                 1-based range
   :B               Repeat each element according to the range ("123" -> "122333")
     X              Save to X register
      %             Length
       m            Map over 1-based range:
        Y             Save index to Y register
         x%           Push length of X register
           {      m   Map over 1-based range:
            y|M         Maximum of both indices
               v        1-based -> 0-based (decrement)
                x@      Index into X register
                      Implicit output with newline

wastl

Posted 2018-06-23T07:34:50.547

Reputation: 3 089

1

Attache, 34 bytes

{_[Table[Max,Flat!{_&_}=>1:#_]-1]}

Try it online!

Explanation

Works similarly to Galen Ivanov's J answer.

{_[Table[Max,Flat!{_&_}=>1:#_]-1]}
{                                }   anonymous function: _ is input, array of digits
                                     example: _ := [2, 0, 3]
                         1:#_        the range 1 to Size[_]
                                     > e.g.: [1, 2, 3]
                  {   }=>            over each number N:
                   _&_                   map to N repeated N times
                                     > e.g.: [[1], [2, 2], [3, 3, 3]]
             Flat!                   flatten it
                                     > e.g.: [1, 2, 2, 3, 3, 3]
   Table[Max,                ]       create a "max" table with it
                                     > e.g.:
                                       1 2 2 3 3 3
                                       2 2 2 3 3 3
                                       2 2 2 3 3 3
                                       3 3 3 3 3 3
                                       3 3 3 3 3 3
                                       3 3 3 3 3 3
                              -1     subtract 1 from each
                                     > e.g.:
                                       0 1 1 2 2 2
                                       1 1 1 2 2 2
                                       1 1 1 2 2 2
                                       2 2 2 2 2 2
                                       2 2 2 2 2 2
                                       2 2 2 2 2 2
 _[                             ]    index the original array with this matrix
                                     > e.g.:
                                       2 0 0 3 3 3
                                       0 0 0 3 3 3
                                       0 0 0 3 3 3
                                       3 3 3 3 3 3
                                       3 3 3 3 3 3
                                       3 3 3 3 3 3

Conor O'Brien

Posted 2018-06-23T07:34:50.547

Reputation: 36 228

1

K (ngn/k), 16 bytes

{x@i|\:i:&1+!#x}

Try it online!

ngn

Posted 2018-06-23T07:34:50.547

Reputation: 11 449

1

C (gcc), 130 bytes

Who needs fancy maths when you can bruteforce?

n,l;R(n,c){for(;n--;)putchar(c);}f(s){for(char*p=s,*q;*p++;)for(n=l=p-s;l--;R(1,10))for(R(n*n+n>>1,p[-1]),q=p;*q;q++)R(q-s+1,*q);}

Try it online!

gastropner

Posted 2018-06-23T07:34:50.547

Reputation: 3 264

1

QBasic, 111 bytes

An anonymous function that prompts for input and outputs to the console.

INPUT s$
n=LEN(s$)
FOR y=1TO n
FOR l=1TO y
?
FOR x=1TO n
z=x
IF y>x THEN z=y
?STRING$(x,MID$(s$,z));
NEXT x,l,y

Taylor Scott

Posted 2018-06-23T07:34:50.547

Reputation: 6 709

Looks good--but don't you mean "full program"? I don't think QBasic has "anonymous functions." – DLosc – 2018-07-05T18:50:02.643

0

Php 7.1, 163 bytes

Via CLI providing the number as an argument:

<?foreach(str_split($argv[1])as$k=>$d)$a[]=array_fill(0,$s+=$k+1,array_fill(0,$s,$d));foreach(array_replace_recursive(...array_reverse($a))as$v)echo join($v)."\n";

Not so golfed:

$n = 123;

foreach(str_split($n) as $k => $d) {
    $s += $k + 1;
    $a[] = array_fill(0, $s, array_fill(0, $s, $d));
}

foreach(array_replace_recursive(...array_reverse($a)) as $v)
    echo implode('', $v) . "\n";

Output:

122333
222333
222333
333333
333333
333333

Method:

Basically build multi-dimensional array squares consisting of the digit, and then superimpose all of them (array_replace_recursive).

(Yes, I know this is embarrassingly long.)

Progrock

Posted 2018-06-23T07:34:50.547

Reputation: 131

If the input is a pre-defined array of digits, and the echo implode/join is removed/replaced with an assignment to a list of list of digits, this can be reduced to about 119 bytes, yep still long. – Progrock – 2018-06-24T12:09:18.740

0

Ruby, 80 bytes

->n{s=(1..n.size).map{|i|n[i-1]*i}*"";(0...s.size).map{|i|s[i]*i+s[i..-1]}*"\n"}

Try it online!

Similar to ovs answer

crashoz

Posted 2018-06-23T07:34:50.547

Reputation: 611

0

Japt, 12 bytes

Takes input as a string, outputs an array of strings.

Ë+pE
¬£h°YçX

Try it


Explanation

            :Implicit input of string U
Ë           :Map each character D at 0-based index E
  pE        :  Repeat D E times
 +          :  Append to D
\n          :Reassign to U
¬           :Split to character array
 £          :Map each element X at 0-based index Y
   °Y       :  Increment Y
     çX     :  Repeat X Y times
  h         :  Replace the first Y characters in U with that

Shaggy

Posted 2018-06-23T07:34:50.547

Reputation: 24 623

0

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!

Taylor Scott

Posted 2018-06-23T07:34:50.547

Reputation: 6 709

0

uBASIC, 120 bytes

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

0Input"",S$:N=Len(S$):ForY=1ToN:ForL=1ToY:ForX=1ToN:ForC=1ToX:Z=X:IfY>XThenZ=Y
1?Mid$(s$,z,1);:NextC:NextX:?:NextL:NextY

Try it online!

Taylor Scott

Posted 2018-06-23T07:34:50.547

Reputation: 6 709

0

Visual Basic .NET (VBC), 198 bytes

A Subroutine that takes input from STDIN and outputs to STDOUT.

Couldn't seem to get StrDup to work :/

Module M
Sub Main
Dim c,s,n,l,x,y
s=Console.readLine()
n=Len(s)
For y=1To n
For l=1To y
For x=1To n
For c=1To x
Console.Write(Mid(s,IIf(x>y,x,y),1)&IIf(c=n,vbLf,""))
Next c,x,l,y 
End Sub
End Module

Try it online!

Taylor Scott

Posted 2018-06-23T07:34:50.547

Reputation: 6 709

0

Lua, 149 140 bytes

Function which accepts a list of digit strings and prints the result to stdout. This is my first attempt at code golf (and the language choice isn't helping either) so bear with me :)

Try it online!

function(a)F,s=0,""for b=1,#a do s=s..a[b]:rep(b)end;for b=1,#a do io.write((s.."\n"):rep(b))F,z=F+b,a[b+1]or""s=z:rep(F)..s:sub(F+1)end end

Ungolfed:

G = function(p)
    F,s = 0,""
    for i=1,#p do
        s=s..p[i]:rep(i)
    end
    for i=1, #p do
        io.write((s.."\n"):rep(i))
        F,z = F+i, p[i+1]or""
        s = z:rep(F)..s:sub(F+1)
    end
end
-- allows to pass the argument list from stdin
-- example: {"1", "2", "3", "4", "5"}
G(load("return " .. io.read())())

PhilipRoman

Posted 2018-06-23T07:34:50.547

Reputation: 151

0

Perl 5 + -nalF -M5.010, 67 bytes

s/./$&x++$-/ge;eval'eval"say;"x++$i;$x+=$i;s/.{$x}/$F[$i]x$x/e;'x@F

Try it online!

Dom Hastings

Posted 2018-06-23T07:34:50.547

Reputation: 16 415