Repeat a string: Difference between revisions

Line 1,158:
<code>concat()</code> joins together a vector of strings, in this case a single string repeated.
<lang parigp>repeat(s,n)=concat(vector(n,i, s));</lang>
 
This solution is recursive and slightly less bad than the others for large n.
<lang parigp>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)
);
}</lang>
 
=={{header|Pascal}}==