2
\$\begingroup\$

For the given string s, generate generate a table like below.

Input:abcd
Output:
abcd
bbcd
cccd
dddd

Input:Hello, world!
Output:
Hello, world!
eello, world!
llllo, world!
llllo, world!
ooooo, world!
,,,,,, world!
       world!
wwwwwwwworld!
ooooooooorld!
rrrrrrrrrrld!
llllllllllld!
dddddddddddd!
!!!!!!!!!!!!!

Trailing whitespace allowed.
This is a code-golf challenge so the shortest solution wins.

\$\endgroup\$
4
  • \$\begingroup\$ Related, related \$\endgroup\$
    – sinvec
    Commented Mar 10, 2022 at 15:10
  • 4
    \$\begingroup\$ I'd lean towards it being too close a duplicate of the linked challenges... was there a discussion on the Sandbox determining otherwise? \$\endgroup\$ Commented Mar 10, 2022 at 15:13
  • 2
    \$\begingroup\$ It kind of combines the two related challenges. \$\endgroup\$
    – Adám
    Commented Mar 10, 2022 at 15:17
  • 6
    \$\begingroup\$ @UnrelatedString it lived in the sandbox for 1 hour, so, no. \$\endgroup\$
    – Giuseppe
    Commented Mar 10, 2022 at 16:05

5 Answers 5

5
\$\begingroup\$

APL (Dyalog Unicode), 12 bytes

Anonymous prefix lambda.

{⍵[∘.⌈⍨⍳≢⍵]}

Try it online!

{} "dfn"; argument is

⍵[] index into characters using the array:

  ≢⍵ tally of characters

   indices of array of that length

  ∘.⌈⍨ maximum-table using that both going down and across

\$\endgroup\$
2
  • \$\begingroup\$ I came up with the same in J, which beats APL by 1 byte this time: {~>./~@i.@# \$\endgroup\$
    – Jonah
    Commented Mar 10, 2022 at 15:50
  • 1
    \$\begingroup\$ @Jonah Yeah, APL is missing { from. I am lobbying for its addition as so we can write ∘.⌈⍨⍤⍳⍤≢⊇⊢ Try it online! \$\endgroup\$
    – Adám
    Commented Mar 10, 2022 at 16:49
2
\$\begingroup\$

BQN, 9 bytesSBCS

Tacit prefix port of my APL answer

⌈⌜˜∘↕∘≠⊸⊏

 maximum-

 table

˜ of self

 of

 the indices

 the string length

⊸⊏ selects characters from that tring

Run online!

\$\endgroup\$
2
\$\begingroup\$

K (ngn/k), 12 bytes

{x@i|\i:!#x}

Try it online!

A port of @Adám's APL answer, using a trick with a seeded scan instead of an each-right or each-left.

  • i:!#x generate list of indices of the input x, storing in i
  • i|\i set up a scan, seeded with i, run over each value in i. this is equivalent to, but one byte shorter, than i|/:i or i|\:i
  • x@ index back into the input, implicitly returning
\$\endgroup\$
1
\$\begingroup\$

Python 3, 45 bytes

lambda s:[s[l]*l+s[l:]for l in range(len(s))]

Try it online!

Inputs a string.
Returns a list of strings.

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

Ruby, 42 bytes

->s{r=0;s.chars.map{|c|s[0,r+=1]=c*r;s.b}}

Try it online!

\$\endgroup\$

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