Exploded Suffixes
Jelly, 5 bytes
ṫJxJY
Try it online! or verify all test cases.
How it works
ṫJxJY Main link. Argument: s (string)
J Indices; yield I := [1, ..., len(s)].
ṫ Tail; get the suffixes of s starting at indices [1, ..., len(s)].
J Indices; yield I again.
x Repeat. The atom 'x' vectorizes at depth 1 (1D arrays of numbers/characters)
in its arguments. This way, each suffix t gets repeated I times, meaning
that the first character of t is repeated once, the second twice, etc.
If left and right argument have different lengths, the longer one is
truncated, so I can safely be applied to all suffixes.
Y Join, separating by linefeeds.
J, 22 12 8 bytes
Thanks to miles for saving 14 bytes!
(#~#\)\.
Now this is a really nice solution. Pretty succinct, too.
This is the hook #~#\
applied to the suffixes (\.
) of the input. The hook, when called on input y
, is decomposed as thus:
(#~#\) y
y #~ #\ y
Here are some intermediate results:
]s =: 's p a c e'
s p a c e
#\ s
1 2 3 4 5 6 7 8 9
(quote) s
's p a c e'
(quote;#)\ s
+-----------+-+
|'s' |1|
+-----------+-+
|'s ' |2|
+-----------+-+
|'s p' |3|
+-----------+-+
|'s p ' |4|
+-----------+-+
|'s p a' |5|
+-----------+-+
|'s p a ' |6|
+-----------+-+
|'s p a c' |7|
+-----------+-+
|'s p a c ' |8|
+-----------+-+
|'s p a c e'|9|
+-----------+-+
1 2 3 # '123'
122333
3 3 3 # '123'
111222333
]\. s
s p a c e
p a c e
p a c e
a c e
a c e
c e
c e
e
e
quote\. s
's p a c e'
' p a c e'
'p a c e'
' a c e'
'a c e'
' c e'
'c e'
' e'
'e'
(#~#\) s
s ppp aaaaa ccccccc eeeeeeeee
(#~#\)\. s
s ppp aaaaa ccccccc eeeeeeeee
pp aaaa cccccc eeeeeeee
p aaa ccccc eeeeeee
aa cccc eeeeee
a ccc eeeee
cc eeee
c eee
ee
e
Test cases
f =: (#~#\)\.
f
(#~ #\)\.
f ''
f 'a'
a
f 'bc'
bcc
c
f 'xyz'
xyyzzz
yzz
z
f 'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f
f 's p a c e'
s ppp aaaaa ccccccc eeeeeeeee
pp aaaa cccccc eeeeeeee
p aaa ccccc eeeeeee
aa cccc eeeeee
a ccc eeeee
cc eeee
c eee
ee
e
]tc =: <;._1 '|' , '|a|bc|xyz|code-golf|s p a c e'
++-+--+---+---------+---------+
||a|bc|xyz|code-golf|s p a c e|
++-+--+---+---------+---------+
,. f &. > tc
+---------------------------------------------+
+---------------------------------------------+
|a |
+---------------------------------------------+
|bcc |
|c |
+---------------------------------------------+
|xyyzzz |
|yzz |
|z |
+---------------------------------------------+
|coodddeeee-----ggggggooooooollllllllfffffffff|
|oddeee----gggggoooooolllllllffffffff |
|dee---ggggooooollllllfffffff |
|e--gggoooolllllffffff |
|-ggooollllfffff |
|goolllffff |
|ollfff |
|lff |
|f |
+---------------------------------------------+
|s ppp aaaaa ccccccc eeeeeeeee|
| pp aaaa cccccc eeeeeeee |
|p aaa ccccc eeeeeee |
| aa cccc eeeeee |
|a ccc eeeee |
| cc eeee |
|c eee |
| ee |
|e |
+---------------------------------------------+
Python, 61 bytes
f=lambda s,i=0:s[i:]and-~i*s[i]+f(s,i+1)or s and'\n'+f(s[1:])
Alternative 63:
f=lambda s,b=1:s and f(s[:-1],0)+s[-1]*len(s)+b*('\n'+f(s[1:]))