2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,3 +1,6 @@
|
|||
Take a string and repeat it some number of times. Example: repeat("ha", 5) => "hahahahaha"
|
||||
Take a string and repeat it some number of times.
|
||||
|
||||
Example: repeat("ha", 5) => "hahahahaha"
|
||||
|
||||
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
|
||||
<br><br>
|
||||
|
|
|
|||
2
Task/Repeat-a-string/APL/repeat-a-string-1.apl
Normal file
2
Task/Repeat-a-string/APL/repeat-a-string-1.apl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
10⍴'ha'
|
||||
hahahahaha
|
||||
3
Task/Repeat-a-string/APL/repeat-a-string-2.apl
Normal file
3
Task/Repeat-a-string/APL/repeat-a-string-2.apl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
REPEAT←{(⍺×⍴⍵)⍴⍵}
|
||||
5 REPEAT 'ha'
|
||||
hahahahaha
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
set str to "ha"
|
||||
set final_string to ""
|
||||
repeat 5 times
|
||||
set final_string to final_string & str
|
||||
set final_string to final_string & str
|
||||
end repeat
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
on run
|
||||
nreps("ha", 50000)
|
||||
end run
|
||||
|
||||
|
||||
-- String -> Int -> String
|
||||
on nreps(s, n)
|
||||
set o to ""
|
||||
if n < 1 then return o
|
||||
|
||||
repeat while (n > 1)
|
||||
if (n mod 2) > 0 then set o to o & s
|
||||
set n to (n div 2)
|
||||
set s to (s & s)
|
||||
end repeat
|
||||
return o & s
|
||||
end nreps
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
FOR I = 1 TO 5 : S$ = S$ + "HA" : NEXT
|
||||
|
||||
? "X" SPC(20) "X"
|
||||
4
Task/Repeat-a-string/Befunge/repeat-a-string.bf
Normal file
4
Task/Repeat-a-string/Befunge/repeat-a-string.bf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
v> ">:#,_v
|
||||
>29*+00p>~:"0"- #v_v $
|
||||
v ^p0p00:-1g00< $ >
|
||||
v p00&p0-1g00+4*65< >00g1-:00p#^_@
|
||||
9
Task/Repeat-a-string/COBOL/repeat-a-string.cobol
Normal file
9
Task/Repeat-a-string/COBOL/repeat-a-string.cobol
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. REPEAT-PROGRAM.
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
77 HAHA PIC A(10).
|
||||
PROCEDURE DIVISION.
|
||||
MOVE ALL 'ha' TO HAHA.
|
||||
DISPLAY HAHA.
|
||||
STOP RUN.
|
||||
8
Task/Repeat-a-string/Elena/repeat-a-string.elena
Normal file
8
Task/Repeat-a-string/Elena/repeat-a-string.elena
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#import system.
|
||||
#import system'routines.
|
||||
#import extensions.
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var s := 0 repeat &till:5 &each: n [ "ha" ] summarize:(String new) literal.
|
||||
].
|
||||
1
Task/Repeat-a-string/Glee/repeat-a-string-1.glee
Normal file
1
Task/Repeat-a-string/Glee/repeat-a-string-1.glee
Normal file
|
|
@ -0,0 +1 @@
|
|||
'*' %% 5
|
||||
4
Task/Repeat-a-string/Glee/repeat-a-string-2.glee
Normal file
4
Task/Repeat-a-string/Glee/repeat-a-string-2.glee
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
'ha' => Str;
|
||||
Str# => Len;
|
||||
1..Len %% (Len * 5) => Idx;
|
||||
Str [Idx] $;
|
||||
1
Task/Repeat-a-string/Glee/repeat-a-string-3.glee
Normal file
1
Task/Repeat-a-string/Glee/repeat-a-string-3.glee
Normal file
|
|
@ -0,0 +1 @@
|
|||
'ha'=>S[1..(S#)%%(S# *5)]
|
||||
8
Task/Repeat-a-string/PARI-GP/repeat-a-string-3.pari
Normal file
8
Task/Repeat-a-string/PARI-GP/repeat-a-string-3.pari
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
repeat(s,n)={
|
||||
if(n<4, return(concat(vector(n,i, s))));
|
||||
if(n%2,
|
||||
Str(repeat(Str(s,s),n\2),s)
|
||||
,
|
||||
repeat(Str(s,s),n\2)
|
||||
);
|
||||
}
|
||||
20
Task/Repeat-a-string/PARI-GP/repeat-a-string-4.pari
Normal file
20
Task/Repeat-a-string/PARI-GP/repeat-a-string-4.pari
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
\\ Repeat a string str the specified number of times ntimes and return composed string.
|
||||
\\ 3/3/2016 aev
|
||||
srepeat(str,ntimes)={
|
||||
my(srez=str,nt=ntimes-1);
|
||||
if(ntimes<1||#str==0,return(""));
|
||||
if(ntimes==1,return(str));
|
||||
for(i=1,nt, srez=concat(srez,str));
|
||||
return(srez);
|
||||
}
|
||||
|
||||
{
|
||||
\\ TESTS
|
||||
print(" *** Testing srepeat:");
|
||||
print("1.",srepeat("a",5));
|
||||
print("2.",srepeat("ab",5));
|
||||
print("3.",srepeat("c",1));
|
||||
print("4.|",srepeat("d",0),"|");
|
||||
print("5.|",srepeat("",5),"|");
|
||||
print1("6."); for(i=1,10000000, srepeat("e",10));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue