| Bytes | Lang | Time | Link |
|---|---|---|---|
| 038 | AWK | 250521T175503Z | xrs |
| nan | Perl 5 | 250521T201232Z | Xcali |
| 003 | Thunno 2 J | 230613T184042Z | The Thon |
| 054 | C clang | 220821T160013Z | c-- |
| 038 | Zsh | 210216T202914Z | pxeger |
| 006 | Brachylog v2 | 230128T114450Z | Unrelate |
| nan | 230128T101855Z | The Thon | |
| 044 | Arturo | 230128T100218Z | chunes |
| 033 | ><> Fish | 221116T164622Z | mousetai |
| 003 | Japt m | 221116T164544Z | Shaggy |
| 014 | Pip | 221116T161642Z | Baby_Boy |
| 069 | Prolog SWI | 220827T203009Z | naffetS |
| 067 | Kustom | 220826T140027Z | Leaf |
| 053 | C# Visual C# Interactive Compiler | 220823T042144Z | Ivan Nee |
| 010 | Burlesque | 220822T190858Z | DeathInc |
| 002 | Jelly | 220822T181632Z | Baby_Boy |
| 008 | BQN | 220821T201543Z | DLosc |
| 002 | Vyxal s | 220821T072925Z | tybocopp |
| 032 | Knight | 220821T040526Z | Sampersa |
| 047 | Dart | 220821T033148Z | user1142 |
| 042 | brev | 220820T083419Z | Sandra |
| 002 | Jelly | 170315T123347Z | Erik the |
| 002 | 05AB1E | 191218T110207Z | Kevin Cr |
| 005 | APL dzaima/APL | 160620T213212Z | Adá |
| 050 | R | 180831T191619Z | Sumner18 |
| 136 | Java | 170316T211113Z | user6333 |
| 058 | Javascript | 170316T055609Z | Kushal B |
| 006 | Siliconnoncompeting | 160630T135455Z | m654 |
| 077 | C | 160622T220604Z | homersim |
| 022 | Retina | 160621T074300Z | Martin E |
| 015 | Brainfuck | 160621T034037Z | Sp3000 |
| 086 | Clojure | 160622T092344Z | cliffroo |
| 084 | C | 160621T202040Z | jqkul |
| 121 | Java | 160620T200327Z | user8397 |
| 041 | Javascript ES6 | 160620T201420Z | Dendrobi |
| 068 | PHP | 160621T143822Z | Simon |
| 125 | Oracle SQL 11.2 | 160621T122421Z | Jeto |
| 082 | LINQPad w/ C# | 160621T111319Z | Sør |
| 046 | Mathematica | 160621T100006Z | LLlAMnYP |
| 032 | Julia | 160621T092336Z | Glen O |
| 097 | TSQL | 160621T084037Z | t-clause |
| 007 | CJam | 160620T204306Z | Martin E |
| 075 | VBA | 160621T065833Z | Joffan |
| 2747 | Python 2.7 47 Bytes | 160621T065316Z | Swadhika |
| 004 | Pyke | 160621T060905Z | Blue |
| 029 | Ruby | 160621T043013Z | Value In |
| 034 | Julia | 160621T041253Z | Dennis |
| 019 | Perl 6 | 160621T032425Z | Brad Gil |
| 039 | Python | 160621T012438Z | Dennis |
| 040 | Python | 160621T010758Z | xnor |
| 014 | K/Kona | 160621T001051Z | Simon Ma |
| 029 | Haskell | 160620T195535Z | nimi |
| 016 | Perl | 160620T232341Z | Doorknob |
| 039 | Javascript ES6 | 160620T212358Z | nderscor |
| 062 | Retina | 160620T220458Z | mbomb007 |
| 004 | J | 160620T211628Z | miles |
| 023 | MATLAB | 160620T211113Z | Suever |
| 005 | MATL | 160620T210657Z | Suever |
| 013 | Brachylog | 160620T204400Z | Fatalize |
| 076 | PHP | 160620T210346Z | InaScuff |
| 081 | C# | 160620T204831Z | ScifiDea |
| 003 | Jelly | 160620T200838Z | Adnan |
| 047 | Python 3 | 160620T200625Z | jqkul |
| 045 | MATLAB | 160620T201100Z | flawr |
| 005 | Pyth | 160620T195954Z | Maltysen |
| 007 | Actually | 160620T200414Z | user4594 |
| 006 | 05AB1E | 160620T200106Z | Emigna |
| 008 | APL | 160620T195249Z | marinus |
| 036 | PowerShell v2+ | 160620T194920Z | AdmBorkB |
Thunno 2 J, 3 bytes
dż×
Explanation
dż× # Implicit input -> "Why"
d # Split into characters -> ["W","h","y"]
ż # Length range -> ["W","h","y"] [1,2,3]
× # Multiply together -> ["W","hh","yyy"]
# Implicit output, joined -> "Whhyyy"
C (clang), 54 bytes
i;c;main(j){for(;j=j-1?:read(0,&c,1)*++i;)putchar(c);}
How it works
i; // declares a zero initialized int
main(j){ // j := argc (should be 1, program called with no arguments)
for(;j=j-1?: // if (j > 1) j = j - 1, otherwise...
read(0,&c,1) // try to read 1 byte, return number of bytes read (0 on EOF or 1)
*++i;) // increment i, j = read? * i (stopping on EOF)
putchar(c); // write to stdout
}
C (clang), 51 bytes
i,j;f(*s){for(i=0;*s;s++)for(j=++i;j--;)printf(s);}
This function takes a wide-character string as input and works in the same way as the full program.
Brachylog v2, 6 bytes
i₁j₎w⊥
Half-port of Fatalize's v1 answer.
i₁ Choose a pair [element, 1-index] from the input.
j₎ Replicate the element by its index.
w Print the result with no trailing newline.
⊥ Backtrack.
Thunno J, \$9\log_{256}(96)\approx\$ 7.41 bytes
DLR1+ZZ.P
Explanation
DLR1+ZZ.P # Implicit input
D # Duplicate
LR # Push range(0, len(input))
1+ # Add one to each
ZZ # Zip with the input
.P # Product of each pair
# Implicit output, joined by J flag
><> (Fish), 33 bytes
1:i:0(?^$:?v~~1+00.
.!02o:$;!-1<|
Basically if the counter is 0 skip to the second :, otherwise the first :. Properly adjust the counters.
Prolog (SWI), 69 bytes
S*O:-append(H,[T],S),maplist([_,Y]>>(Y=T),S,R),H*Y,append(Y,R,O);O=S.
I feel like this should be shorter...
Kustom, 67 bytes
This makes use of the fact that an undefined global variable works as empty string. The extra byte is for the name of the defined global variable.
$fl(1,tc(len,gv(n)),"i+1","tc(lpad,gv(x),i,tc(cut,gv(n),i-1,1))")$
Sort of ungolfed:
$fl(
1,
tc(len, gv(input)),
"i + 1",
"tc(
lpad,
gv(undefined),
i,
tc(
cut,
gv(input),
i - 1,
1
)
)"
)$
C# (Visual C# Interactive Compiler), 53 bytes
a=>string.Concat(a.Select((c,i)=>new@String(c,i+1)));
Burlesque, 10 bytes
{+..*}wi\[
{
+. # Increment
.* # Repeat
}wi # Apply with 0-index
\[ # Concatenate
BQN, 9 8 bytes
⊢/˜1+↕∘≠
Anonymous tacit function. Try it at BQN online!
Explanation
⊢/˜1+↕∘≠
≠ Length of argument
↕∘ Range
1+ Add 1 to each, making it an inclusive range from 1 to the length
/˜ Replicate that many times the elements of
⊢ The original input
Knight, 33 32 bytes
;=i!=sP;W<iLsO+*Gs iT=i+1i"\"O""
expanded:
; = i ! = s PROMPT
; WHILE < i LENGTH s
: OUTPUT
+
* (GET s i TRUE) (= i + 1 i)
"\" # so no trailing newline
: OUTPUT "" # now output the trailing newline
-1 did =i! instead of ;=iF
brev, 42 bytes
(as-list flatten(over(make-list(+ i 1)x)))
05AB1E, 2 bytes
ƶJ
Try it online or verify all test cases.
Explanation:
ƶ # Multiply each character in the (implicit) input-string by its 1-based index
J # Join the list of substrings together to a single string
# (after which the result is output implicitly)
APL (dzaima/APL), 6 5 bytes
⍳∘≢⌿⊢
⍳∘≢ enumeration of the argument... (indices of its length)
⌿ replicates the elements of...
⊢ the unmodified argument
R, 83 50 bytes
-23 Thanks to Giuseppe, though he used essentially an entire new method altogether
function(s)intToUtf8(rep(utf8ToInt(s),1:nchar(s)))
My original post:
function(s){r="";for(i in 1:nchar(s))r=paste0(r,strrep(el(strsplit(s,""))[i],i));r}
I feel like there's definitely a better way to do this, but with my new knowledge of a few functions in R, this is my approach.
Java, 136 bytes
enum b{;public static void main(String[]a){int i=0,j=0;for(;i<a[0].length();i++){for(;j<i+1;j++)System.out.print(a[0].charAt(i));j=0;}}}
Takes input as program arguments.
Ungolfed with comments:
enum b {;
public static void main(String[]a) {
int i=0, j=0; // Init counters
for (; i<a[0].length(); i++) { // For each characters in string
for (; j < i + 1; j++) // Loop from 0 to i
System.out.print(a[0].charAt(i)); // Print character at i
j=0; // Reset j
}
}
}
Javascript, 58 bytes
e=a=>(Array.from(a).map((e,i)=>(e).repeat(i+1))).join("");
Silicon(non-competing), 6 bytes
(This language is exactly the same age as this challenge, but I added some useful commands right after I saw it, so non-competing I think.)
biSÚÿj
Silicon uses CP037, which is a 255-bit codepage.
Explanation:
b Push a space
i Input
S Split
Ú Enumerate
ÿ Replicate each list item n times
j Join
C, 77 bytes
Not much room for golfing here. If only there were a string repeat operator.
i;main(j){char s[999];gets(s);for(;s[i];i++)for(j=0;j<=i;j++)putchar(s[i]);}
Try it online! http://ideone.com/UliJfD
Retina, 22 bytes
Byte count assumes ISO 8859-1 encoding.
.
$&$.`$*·
+`(.)·
$1$1
Basically, we insert the right amount of · as placeholders between the characters (since these extended ASCII characters can't appear in the input), then fill them up with the adjacent character in the second stage.
Brainfuck, 15 bytes
,[>+[->+<<.>],]
Pretty straightforward implementation, shifting the memory space by 1 for each input char. Requires an interpreter that gives 0 on EOF, and 32-bit/arbitrary precision cells for inputs longer than 255 chars.
Try it online! (Note: TIO uses 8-bit cells)
Clojure, 86 bytes
(fn[s](apply str(mapcat #(repeat(+(nth % 1)1)(nth % 0))(map list s(range(count s))))))
Well, nearly beat C. Create a list of pairs (symbol, its position), then repeat each symbol given number of times and flatten the result list and concatenate the list into one string.
See it here: https://ideone.com/uQNar2
C, 84 bytes
main(c,v,i,j)char**v;{for(i=0;i<strlen(v[1]);++i)for(j=0;j<=i;++j)putchar(v[1][i]);}
This should compile on gcc with no flags. Input is taken through the first command-line argument. E.g.
$ ./elasticize Why
Whhyyy
$ ./elasticize SKype
SKKyyyppppeeeee
$ ./elasticize LobbY
LoobbbbbbbYYYYY
$ ./elasticize A and B
A aaannnnddddd BBBBBBB
Ungolfed:
int main(int argc, char** argv) {
int i, j;
for(i = 0; i < strlen(argv[1]); ++i) {
for(j = 0; j <= i; ++j) {
putchar(v[1][i]);
}
}
}
Java, 158 121 bytes
Saved a whopping 37 bytes thanks to Kevin Cruijssen!
interface a{static void main(String[]A){int b=0,B;for(char c:A[0].toCharArray())for(B=b+++2;--B>0;)System.out.print(c);}}
As a bonus, this program can handle all Unicode characters in the existence, including the control characters located at the very end of Basic Multilingual Plane.
Javascript ES6, 42 41 bytes
s=>[,...s].map((e,i)=>e.repeat(i)).join``
Example runs:
f=s=>[,...s].map((e,i)=>e.repeat(i)).join``
f("Why") => "Whhyyy"
f("SKype") => "SKKyyyppppeeeee"
f("LobbY") => "LoobbbbbbbYYYYY"
PHP, 68 bytes
<?php foreach(str_split($argv[1])as$i=>$a)echo str_repeat($a,$i+1);
Oracle SQL 11.2, 125 bytes
SELECT LISTAGG(SUBSTR(RPAD(' ',LEVEL+1,SUBSTR(:1,LEVEL,1)),2))WITHIN GROUP(ORDER BY 1)FROM DUAL CONNECT BY LEVEL<=LENGTH(:1);
LINQPad w/ C#, 82 bytes
void m(string s){Console.Write(s.SelectMany((x,i)=>new string(x,++i)).ToArray());}
Single output operation.
Mathematica, 46 bytes
""<>Table@@@(#^Range@Length@#&@Characters[#])&
Unnamed function. Takes the characters of the input string and raises them to the power of their position in the string (i.e. "abc" becomes {"a"^1, "b"^2, "c"^3}). Yes, MMA don't give a shit 'bout types :-)
The FullForm of the above list elements is Power["a", 1], etc.
Table@@@ acts on the list, replacing the head of each element (in this case Power) with Table.
Results in {Table["a"], Table["b", 2], Table["c", 3]} (because "a"^1 -> "a").
This evaluates to {"a", {"b", "b"}, {"c", "c", "c"}} Finally the infix concatenation operator <> concatenates this with the empty string.
I exploited the fact that Power is Listable, i.e. it automatically threads over corresponding elements of lists, but not orderless (because "a" + 1 would evaluate to Plus[1, "a"]).
Julia, 32 bytes
!s=join(split(s[k=1:end],"").^k)
Unlike Dennis's solution, this is not recursive. split with argument "" separates the string into an array of strings of length 1. The [k=1:end] is a trick to create a range from 1 to the number of characters in the string, and this range is used to concatenate n copies of the n-th character. join then recombines the array of strings into a single string, in order.
Usage example: !"SKype"
TSQL, 97 bytes
Golfed:
DECLARE @x varchar(max)='Lobby'
DECLARE @ int=LEN(@x)WHILE @>0SELECT
@x=STUFF(@x,@,1,REPLICATE(SUBSTRING(@x,@,1),@)),@-=1PRINT @x
Ungolfed:
DECLARE @x varchar(max)='Lobby'
DECLARE @ int=LEN(@x)
WHILE @>0
SELECT
@x=STUFF(@x,@,1,REPLICATE(SUBSTRING(@x,@,1),@)),
@-=1
PRINT @x
CJam, 9 8 7 bytes
Thanks to jimmy23013 for saving 1 byte.
Sl+eee~
Explanation
Using the LobbY example:
Stack:
S e# Push space. [" "]
l e# Read input. [" " "LobbY"]
+ e# Append. [" LobbY"]
ee e# Enumerate. [[[0 ' ] [1 'L] [2 'o] [3 'b] [4 'b] [5 'Y]]]
e~ e# Run-length decode. ["LoobbbbbbbYYYYY"]
VBA, 75 bytes
Function e(s):For a=1 To Len(s):e=e &String(a,Mid(s,a,1)):Next:End Function
Call as e.g. a user function in a spreadsheet.
=e(A1)
┌─────────┬───────────────┐
│ SKype │SKKyyyppppeeeee│
└─────────┴───────────────┘
It truncates if you feed it its own output a few times :-).
Python 2.7 - 47 Bytes
''.join([s[i-1]*i for i in range(1, len(s)+1)])
where 's' is the given string Output:
welcome: weelllccccooooommmmmmeeeeeee
00004: 000000000044444
Why: Whhyyy
SKype: SKKyyyppppeeeee
A and B: A aaannnnddddd BBBBBBB
Perl 6, 22 20 19 bytes
{S:g/(.)/{$0 x$/.to}/}
{S:g[(.)]=$0 x$/.to}
{[~] .comb Zx 1..*}
Explanation:
{ # implicit parameter $_
[~] # string concatenate the following list
.comb # the NFG characters from $_
Z[x] # zip combined using the string repetition operator
1 .. * # 1 to infinity
}
Python, 40 bytes
f=lambda s,i=1:s and s[0]*i+f(s[1:],i+1)
Haskell, 29 bytes
concat.zipWith replicate[1..]
Usage example: concat.zipWith replicate[1..] $ "SKype" -> "SKKyyyppppeeeee".
replicate n c makes n copies of c and concat makes a single list out of all the sublists.
Perl, 16 bytes
s/./$&x$+[0]/ge
+1 byte for the -p flag.
s/./ / find every character
g globally
e and replace with the eval'd result of
$& the matched string
x repeated
$+[0] by the index of the character after the match
Javascript ES6, 39 bytes
x=>x.replace(/./g,(y,i)=>y+y.repeat(i))
Same length, but more fun:
x=>x.replace(i=/./g,y=>y.repeat(i=-~i))
Snippet demo:
f= x=>x.replace(/./g,(y,i)=>y+y.repeat(i))
run.onclick=_=>output.textContent=f(input.value)
<input id="input" value="SKype">
<button id="run">Go</button>
<pre id="output"></pre>
Retina, 62 bytes
It wasn't as easy or short as I thought it'd be. Note that the code contains no spaces. They are all tabs (which are rendered incorrectly here), and the last line is blank.
.*
$0¶ ¶
{+`^(.)(.*)¶ (.*¶.*)
$1$2 ¶$3$1
( +)¶
¶ $1
}`^.
|¶
J, 4 bytes
#~#\
Usage
f =: #~#\
f 'Why'
Whhyyy
f 'SKype'
SKKyyyppppeeeee
f 'LobbY'
LoobbbbbbbYYYYY
f 'A and B'
A aaannnnddddd BBBBBBB
Explanation
#~#\ Input: s
#\ Computes the length of each prefix of s
This forms the range [1, 2, ..., len(s)]
#~ For each value in the range, copy the character at the
corresponding index that many times
Return the created string
MATLAB, 23 bytes
@(x)repelem(x,1:nnz(x))
Creates an anonymous function ans that can be called using ans('stringtoelacticize')
MATL, 5 bytes
tn:Y"
Explanation
% Implictly grab input as a string
tn % Duplicate and compute the length (N)
: % Create an array from [1...N]
Y" % Perform run-length decoding to elacticize the string
% Implicitly display the result
Brachylog, 13 bytes
:ImC,0:Ie,Cw\
This prints the result to STDOUT.
Explanation
This is a good example of exploiting backtracking to loop.
:ImC C is the Ith character of the Input
,
0:Ie Unify an implicit variable with an integer between 0 and I
,
Cw Write C to STDOUT
\ False, trigger backtracking. It will go back to 0:Ie and unify the implicit
variable with another integer, until all integers were used. After that, it
will backtrack to :ImC and unify I and C with the next character.
PHP, 76 bytes
I'm sure this can be improved...
<?php for($i=0;$i<strlen($argv[1]);$i++)echo str_repeat($argv[1]{$i},$i+1);
Run from command line:
$ php [file] "Testing"
C#, 81 Bytes
void f(string s){for(int i=0;i<s.Length;i++)Console.Write(new String(s[i],i+1));}
Jelly, 3 bytes
Code:
ĖP€
Explanation:
Ė # Enumerate.
P€ # Product of each.
# Implicit joining of everything.
Uses the Jelly encoding. Try it online!.
Python 3, 48 47 bytes
Thanks to mego for saving a byte with the -~i trick.
lambda s:''.join(c*-~i for i,c in enumerate(s))
This is mostly self-explanatory. One thing for those not versed in Python: The * operator is overloaded to act like Perl's x operator, repeating its string argument the number of times specified by its numeric argument. E.g. 'foo' * 3 == 'foofoofoo'
MATLAB, 45 bytes
g=@(m)sort(m(m>0));@(s)s(g(hankel(1:nnz(s))))
Explanation: The key is hankel, which produces a Hankel matrix of a given vector. From this matrix, we can extract a vector of indices, which defines which character of the string is at which position in the output. E.g. hankel(1:4) produces following matrix:
1 2 3 4
2 3 4 0
3 4 0 0
4 0 0 0
From this matrix we can extrac the vector 1,2,2,3,3,3,4,4,4,4,4. This vector allows us to output the first character of the string once, the second one twice e.t.c.
Actually, 7 bytes
' +ñ♂πΣ
Explanation:
' +ñ♂πΣ
' + prepend a space
ñ enumerate ("abc" -> [[0, 'a'], [1, 'b'], [2, 'c']])
♂π map: for each character, repeat it n times
Σ concatenate
05AB1E, 6 bytes
vN>Fy?
Explained
v # for each char in string
N>F # index+1 number of times do
y? # print current char
APL (8)
{⍵/⍨⍳⍴⍵}
I.e.:
{⍵/⍨⍳⍴⍵} ¨ 'Why' 'SKype' 'LobbY'
┌──────┬───────────────┬───────────────┐
│Whhyyy│SKKyyyppppeeeee│LoobbbbbbbYYYYY│
└──────┴───────────────┴───────────────┘
Explanation:
⍴⍵: length of given vector⍳: numbers 1..N⍵/⍨: replicate each element in⍵N times.
PowerShell v2+, 36 bytes
-join([char[]]$args[0]|%{"$_"*++$i})
Takes input $args[0], explicitly casts it as a char array, sends that into a loop |%{...}. Each iteration we take the current letter/character "$_" and use the * overloaded operator to concatenate the string pre-incremented $i times. The result of each loop iteration is encapsulated in parens to form an array and then -joined together to form a string. That string is left on the pipeline and output is implicit.
Examples
PS C:\Tools\Scripts\golfing> .\elasticize-a-word.ps1 Why
Whhyyy
PS C:\Tools\Scripts\golfing> .\elasticize-a-word.ps1 SKype
SKKyyyppppeeeee
PS C:\Tools\Scripts\golfing> .\elasticize-a-word.ps1 LobbY
LoobbbbbbbYYYYY
PS C:\Tools\Scripts\golfing> .\elasticize-a-word.ps1 'a b'
a bbb
