2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -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>

View file

@ -0,0 +1,2 @@
10'ha'
hahahahaha

View file

@ -0,0 +1,3 @@
REPEAT{(×)}
5 REPEAT 'ha'
hahahahaha

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,3 @@
FOR I = 1 TO 5 : S$ = S$ + "HA" : NEXT
? "X" SPC(20) "X"

View file

@ -0,0 +1,4 @@
v> ">:#,_v
>29*+00p>~:"0"- #v_v $
v ^p0p00:-1g00< $ >
v p00&p0-1g00+4*65< >00g1-:00p#^_@

View 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.

View 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.
].

View file

@ -0,0 +1 @@
'*' %% 5

View file

@ -0,0 +1,4 @@
'ha' => Str;
Str# => Len;
1..Len %% (Len * 5) => Idx;
Str [Idx] $;

View file

@ -0,0 +1 @@
'ha'=>S[1..(S#)%%(S# *5)]

View 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)
);
}

View 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));
}