tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
3
Task/Repeat-a-string/0DESCRIPTION
Normal file
3
Task/Repeat-a-string/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
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) => "*****").
|
||||
2
Task/Repeat-a-string/1META.yaml
Normal file
2
Task/Repeat-a-string/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: String manipulation
|
||||
10
Task/Repeat-a-string/4DOS-Batch/repeat-a-string.4dos
Normal file
10
Task/Repeat-a-string/4DOS-Batch/repeat-a-string.4dos
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
gosub repeat ha 5
|
||||
echo %@repeat[*,5]
|
||||
quit
|
||||
|
||||
:Repeat [String Times]
|
||||
do %Times%
|
||||
echos %String%
|
||||
enddo
|
||||
echo.
|
||||
return
|
||||
1
Task/Repeat-a-string/ALGOL-68/repeat-a-string.alg
Normal file
1
Task/Repeat-a-string/ALGOL-68/repeat-a-string.alg
Normal file
|
|
@ -0,0 +1 @@
|
|||
print (5 * "ha")
|
||||
10
Task/Repeat-a-string/AWK/repeat-a-string.awk
Normal file
10
Task/Repeat-a-string/AWK/repeat-a-string.awk
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
function repeat( str, n, rep, i )
|
||||
{
|
||||
for( ; i<n; i++ )
|
||||
rep = rep str
|
||||
return rep
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
print repeat( "ha", 5 )
|
||||
}
|
||||
7
Task/Repeat-a-string/ActionScript/repeat-a-string-1.as
Normal file
7
Task/Repeat-a-string/ActionScript/repeat-a-string-1.as
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function repeatString(string:String, numTimes:uint):String
|
||||
{
|
||||
var output:String = "";
|
||||
for(var i:uint = 0; i < numTimes; i++)
|
||||
output += string;
|
||||
return output;
|
||||
}
|
||||
7
Task/Repeat-a-string/ActionScript/repeat-a-string-2.as
Normal file
7
Task/Repeat-a-string/ActionScript/repeat-a-string-2.as
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function repeatRecursive(string:String, numTimes:uint):String
|
||||
{
|
||||
if(numTimes == 0) return "";
|
||||
if(numTimes & 1) return string + repeatRecursive(string, numTimes - 1);
|
||||
var tmp:String = repeatRecursive(string, numTimes/2);
|
||||
return tmp + tmp;
|
||||
}
|
||||
2
Task/Repeat-a-string/ActionScript/repeat-a-string-3.as
Normal file
2
Task/Repeat-a-string/ActionScript/repeat-a-string-3.as
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import mx.utils.StringUtil;
|
||||
trace(StringUtil.repeat("ha", 5));
|
||||
7
Task/Repeat-a-string/Ada/repeat-a-string.ada
Normal file
7
Task/Repeat-a-string/Ada/repeat-a-string.ada
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure String_Multiplication is
|
||||
begin
|
||||
Put_Line (5 * "ha");
|
||||
end String_Multiplication;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
set str to "ha"
|
||||
set final_string to ""
|
||||
repeat 5 times
|
||||
set final_string to final_string & str
|
||||
end repeat
|
||||
8
Task/Repeat-a-string/AutoHotkey/repeat-a-string.ahk
Normal file
8
Task/Repeat-a-string/AutoHotkey/repeat-a-string.ahk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
MsgBox % Repeat("ha",5)
|
||||
|
||||
Repeat(String,Times)
|
||||
{
|
||||
Loop, %Times%
|
||||
Output .= String
|
||||
Return Output
|
||||
}
|
||||
1
Task/Repeat-a-string/BBC-BASIC/repeat-a-string.bbc
Normal file
1
Task/Repeat-a-string/BBC-BASIC/repeat-a-string.bbc
Normal file
|
|
@ -0,0 +1 @@
|
|||
PRINT STRING$(5, "ha")
|
||||
3
Task/Repeat-a-string/Babel/repeat-a-string-1.pb
Normal file
3
Task/Repeat-a-string/Babel/repeat-a-string-1.pb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
main: { "ha" 5 print_repeat }
|
||||
|
||||
print_repeat!: { <- { dup << } -> times }
|
||||
1
Task/Repeat-a-string/Babel/repeat-a-string-2.pb
Normal file
1
Task/Repeat-a-string/Babel/repeat-a-string-2.pb
Normal file
|
|
@ -0,0 +1 @@
|
|||
hahahahaha
|
||||
8
Task/Repeat-a-string/Batch-File/repeat-a-string-1.bat
Normal file
8
Task/Repeat-a-string/Batch-File/repeat-a-string-1.bat
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
@echo off
|
||||
if "%2" equ "" goto fail
|
||||
setlocal enabledelayedexpansion
|
||||
set char=%1
|
||||
set num=%2
|
||||
for /l %%i in (1,1,%num%) do set res=!res!%char%
|
||||
echo %res%
|
||||
:fail
|
||||
10
Task/Repeat-a-string/Batch-File/repeat-a-string-2.bat
Normal file
10
Task/Repeat-a-string/Batch-File/repeat-a-string-2.bat
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
@echo off
|
||||
set /p a=Enter string to repeat :
|
||||
set /p b=Enter how many times to repeat :
|
||||
set "c=1"
|
||||
set "d=%b%"
|
||||
:a
|
||||
echo %a%
|
||||
set "c=%c%+=1"
|
||||
if /i _"%c%"==_"%d%" (exit /b)
|
||||
goto :a
|
||||
13
Task/Repeat-a-string/Batch-File/repeat-a-string-3.bat
Normal file
13
Task/Repeat-a-string/Batch-File/repeat-a-string-3.bat
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
@echo off
|
||||
@FOR /L %%i in (0,1,9) DO @CALL :REPEAT %%i
|
||||
@echo That's it!
|
||||
@FOR /L %%i in (0,1,9) DO @CALL :REPEAT %%i
|
||||
@echo.
|
||||
@echo And that!
|
||||
@GOTO END
|
||||
|
||||
:REPEAT
|
||||
@echo|set /p="*"
|
||||
@GOTO:EOF
|
||||
|
||||
:END
|
||||
8
Task/Repeat-a-string/Bracmat/repeat-a-string.bracmat
Normal file
8
Task/Repeat-a-string/Bracmat/repeat-a-string.bracmat
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(repeat=
|
||||
string N rep
|
||||
. !arg:(?string.?N)
|
||||
& !string:?rep
|
||||
& whl
|
||||
' (!N+-1:>0:?N&!string !rep:?rep)
|
||||
& str$!rep
|
||||
);
|
||||
9
Task/Repeat-a-string/Brainf---/repeat-a-string.bf
Normal file
9
Task/Repeat-a-string/Brainf---/repeat-a-string.bf
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
+++++ +++++ init first as 10 counter
|
||||
[-> +++++ +++++<] we add 10 to second each loopround
|
||||
|
||||
Now we want to loop 5 times to follow std
|
||||
+++++
|
||||
[-> ++++ . ----- -- . +++<] print h and a each loop
|
||||
|
||||
and a newline because I'm kind and it looks good
|
||||
+++++ +++++ +++ . --- .
|
||||
1
Task/Repeat-a-string/Brat/repeat-a-string.brat
Normal file
1
Task/Repeat-a-string/Brat/repeat-a-string.brat
Normal file
|
|
@ -0,0 +1 @@
|
|||
p "ha" * 5 #Prints "hahahahaha"
|
||||
4
Task/Repeat-a-string/Burlesque/repeat-a-string.blq
Normal file
4
Task/Repeat-a-string/Burlesque/repeat-a-string.blq
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
blsq ) 'h5?*
|
||||
"hhhhh"
|
||||
blsq ) "ha"5.*\[
|
||||
"hahahahaha"
|
||||
15
Task/Repeat-a-string/C++/repeat-a-string-1.cpp
Normal file
15
Task/Repeat-a-string/C++/repeat-a-string-1.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
std::string repeat( const std::string &word, int times ) {
|
||||
std::string result ;
|
||||
result.reserve(times*word.length()); // avoid repeated reallocation
|
||||
for ( int a = 0 ; a < times ; a++ )
|
||||
result += word ;
|
||||
return result ;
|
||||
}
|
||||
|
||||
int main( ) {
|
||||
std::cout << repeat( "Ha" , 5 ) << std::endl ;
|
||||
return 0 ;
|
||||
}
|
||||
7
Task/Repeat-a-string/C++/repeat-a-string-2.cpp
Normal file
7
Task/Repeat-a-string/C++/repeat-a-string-2.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
int main( ) {
|
||||
std::cout << std::string( 5, '*' ) << std::endl ;
|
||||
return 0 ;
|
||||
}
|
||||
1
Task/Repeat-a-string/C-sharp/repeat-a-string-1.cs
Normal file
1
Task/Repeat-a-string/C-sharp/repeat-a-string-1.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
string s = "".PadLeft(5, 'X').Replace("X", "ha");
|
||||
1
Task/Repeat-a-string/C-sharp/repeat-a-string-2.cs
Normal file
1
Task/Repeat-a-string/C-sharp/repeat-a-string-2.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
string s = new String('X', 5).Replace("X", "ha");
|
||||
1
Task/Repeat-a-string/C-sharp/repeat-a-string-3.cs
Normal file
1
Task/Repeat-a-string/C-sharp/repeat-a-string-3.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
string s = String.Join("ha", new string[5 + 1]);
|
||||
1
Task/Repeat-a-string/C-sharp/repeat-a-string-4.cs
Normal file
1
Task/Repeat-a-string/C-sharp/repeat-a-string-4.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
string s = String.Concat(Enumerable.Repeat("ha", 5));
|
||||
1
Task/Repeat-a-string/C-sharp/repeat-a-string-5.cs
Normal file
1
Task/Repeat-a-string/C-sharp/repeat-a-string-5.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
string s = "".PadLeft(5, '*');
|
||||
1
Task/Repeat-a-string/C-sharp/repeat-a-string-6.cs
Normal file
1
Task/Repeat-a-string/C-sharp/repeat-a-string-6.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
string s = new String('*', 5);
|
||||
22
Task/Repeat-a-string/C/repeat-a-string-1.c
Normal file
22
Task/Repeat-a-string/C/repeat-a-string-1.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char * string_repeat( int n, const char * s ) {
|
||||
size_t slen = strlen(s);
|
||||
char * dest = malloc(n*slen+1);
|
||||
|
||||
int i; char * p;
|
||||
for ( i=0, p = dest; i < n; ++i, p += slen ) {
|
||||
memcpy(p, s, slen);
|
||||
}
|
||||
*p = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char * result = string_repeat(5, "ha")
|
||||
puts(result);
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
13
Task/Repeat-a-string/C/repeat-a-string-2.c
Normal file
13
Task/Repeat-a-string/C/repeat-a-string-2.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
...
|
||||
char *string_repeat(const char *str, int n)
|
||||
{
|
||||
char *pa, *pb;
|
||||
size_t slen = strlen(str);
|
||||
char *dest = malloc(n*slen+1);
|
||||
|
||||
pa = dest + (n-1)*slen;
|
||||
strcpy(pa, str);
|
||||
pb = --pa + slen;
|
||||
while (pa>=dest) *pa-- = *pb--;
|
||||
return dest;
|
||||
}
|
||||
17
Task/Repeat-a-string/C/repeat-a-string-3.c
Normal file
17
Task/Repeat-a-string/C/repeat-a-string-3.c
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char * char_repeat( int n, char c ) {
|
||||
char * dest = malloc(n+1);
|
||||
memset(dest, c, n);
|
||||
dest[n] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char * result = char_repeat(5, '*');
|
||||
puts(result);
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
1
Task/Repeat-a-string/Clojure/repeat-a-string.clj
Normal file
1
Task/Repeat-a-string/Clojure/repeat-a-string.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(apply str (repeat 5 "ha"))
|
||||
5
Task/Repeat-a-string/Common-Lisp/repeat-a-string-1.lisp
Normal file
5
Task/Repeat-a-string/Common-Lisp/repeat-a-string-1.lisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defun repeat-string (n string)
|
||||
(with-output-to-string (stream)
|
||||
(loop repeat n do (write-string string stream))))
|
||||
|
||||
(princ (repeat-string 5 "hi"))
|
||||
1
Task/Repeat-a-string/Common-Lisp/repeat-a-string-2.lisp
Normal file
1
Task/Repeat-a-string/Common-Lisp/repeat-a-string-2.lisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(make-string 5 :initial-element #\X)
|
||||
5
Task/Repeat-a-string/D/repeat-a-string-1.d
Normal file
5
Task/Repeat-a-string/D/repeat-a-string-1.d
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import std.stdio, std.array;
|
||||
|
||||
void main() {
|
||||
writeln("ha".replicate(5));
|
||||
}
|
||||
8
Task/Repeat-a-string/D/repeat-a-string-2.d
Normal file
8
Task/Repeat-a-string/D/repeat-a-string-2.d
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
char[] chars; // create the dynamic array
|
||||
chars.length = 5; // set the length
|
||||
chars[] = '*'; // set all characters in the string to '*'
|
||||
writeln(chars);
|
||||
}
|
||||
1
Task/Repeat-a-string/DWScript/repeat-a-string-1.dwscript
Normal file
1
Task/Repeat-a-string/DWScript/repeat-a-string-1.dwscript
Normal file
|
|
@ -0,0 +1 @@
|
|||
PrintLn( StringOfString('abc',5) );
|
||||
1
Task/Repeat-a-string/DWScript/repeat-a-string-2.dwscript
Normal file
1
Task/Repeat-a-string/DWScript/repeat-a-string-2.dwscript
Normal file
|
|
@ -0,0 +1 @@
|
|||
PrintLn( StringOfChar('a',5) );
|
||||
9
Task/Repeat-a-string/Delphi/repeat-a-string-1.delphi
Normal file
9
Task/Repeat-a-string/Delphi/repeat-a-string-1.delphi
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function RepeatString(const s: string; count: cardinal): string;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 1 to count do
|
||||
Result := Result + s;
|
||||
end;
|
||||
|
||||
Writeln(RepeatString('ha',5));
|
||||
1
Task/Repeat-a-string/Delphi/repeat-a-string-2.delphi
Normal file
1
Task/Repeat-a-string/Delphi/repeat-a-string-2.delphi
Normal file
|
|
@ -0,0 +1 @@
|
|||
Writeln( StringOfChar('a',5) );
|
||||
1
Task/Repeat-a-string/Delphi/repeat-a-string-3.delphi
Normal file
1
Task/Repeat-a-string/Delphi/repeat-a-string-3.delphi
Normal file
|
|
@ -0,0 +1 @@
|
|||
StrUtils.DupeString
|
||||
1
Task/Repeat-a-string/E/repeat-a-string.e
Normal file
1
Task/Repeat-a-string/E/repeat-a-string.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
"ha" * 5
|
||||
2
Task/Repeat-a-string/Erlang/repeat-a-string.erl
Normal file
2
Task/Repeat-a-string/Erlang/repeat-a-string.erl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
repeat(X,N) ->
|
||||
lists:flatten(lists:duplicate(N,X)).
|
||||
16
Task/Repeat-a-string/Euphoria/repeat-a-string-1.euphoria
Normal file
16
Task/Repeat-a-string/Euphoria/repeat-a-string-1.euphoria
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function repeat_string(object x, integer times)
|
||||
sequence out
|
||||
if atom(x) then
|
||||
return repeat(x,times)
|
||||
else
|
||||
out = ""
|
||||
for n = 1 to times do
|
||||
out &= x
|
||||
end for
|
||||
return out
|
||||
end if
|
||||
end function
|
||||
|
||||
puts(1,repeat_string("ha",5) & '\n') -- hahahahaha
|
||||
|
||||
puts(1,repeat_string('*',5) & '\n') -- *****
|
||||
4
Task/Repeat-a-string/Euphoria/repeat-a-string-2.euphoria
Normal file
4
Task/Repeat-a-string/Euphoria/repeat-a-string-2.euphoria
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
-- Here is an alternative method for "Repeat a string"
|
||||
include std/sequence.e
|
||||
printf(1,"Here is the repeated string: %s\n", {repeat_pattern("ha",5)})
|
||||
printf(1,"Here is another: %s\n", {repeat_pattern("*",5)})
|
||||
3
Task/Repeat-a-string/Factor/repeat-a-string.factor
Normal file
3
Task/Repeat-a-string/Factor/repeat-a-string.factor
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
: repeat-string ( str n -- str' ) swap <repetition> concat ;
|
||||
|
||||
"ha" 5 repeat-string print
|
||||
6
Task/Repeat-a-string/Forth/repeat-a-string-1.fth
Normal file
6
Task/Repeat-a-string/Forth/repeat-a-string-1.fth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
: place-n { src len dest n -- }
|
||||
0 dest c!
|
||||
n 0 ?do src len dest +place loop ;
|
||||
|
||||
s" ha" pad 5 place-n
|
||||
pad count type \ hahahahaha
|
||||
7
Task/Repeat-a-string/Forth/repeat-a-string-2.fth
Normal file
7
Task/Repeat-a-string/Forth/repeat-a-string-2.fth
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
: place-n ( src len dest n -- )
|
||||
swap >r 0 r@ c!
|
||||
begin dup while -rot 2dup r@ +place rot 1- repeat
|
||||
r> 2drop 2drop ;
|
||||
|
||||
s" ha" pad 5 place-n
|
||||
pad count type \ hahahahaha
|
||||
2
Task/Repeat-a-string/Forth/repeat-a-string-3.fth
Normal file
2
Task/Repeat-a-string/Forth/repeat-a-string-3.fth
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pad 10 char * fill \ repeat a single character
|
||||
pad 10 type \ **********
|
||||
5
Task/Repeat-a-string/Fortran/repeat-a-string.f
Normal file
5
Task/Repeat-a-string/Fortran/repeat-a-string.f
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
program test_repeat
|
||||
|
||||
write (*, '(a)') repeat ('ha', 5)
|
||||
|
||||
end program test_repeat
|
||||
1
Task/Repeat-a-string/Frink/repeat-a-string.frink
Normal file
1
Task/Repeat-a-string/Frink/repeat-a-string.frink
Normal file
|
|
@ -0,0 +1 @@
|
|||
println[repeat["ha", 5]]
|
||||
2
Task/Repeat-a-string/GAP/repeat-a-string.gap
Normal file
2
Task/Repeat-a-string/GAP/repeat-a-string.gap
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Concatenation(List([1 .. 10], n -> "BOB "));
|
||||
# "BOB BOB BOB BOB BOB BOB BOB BOB BOB BOB "
|
||||
1
Task/Repeat-a-string/Go/repeat-a-string-1.go
Normal file
1
Task/Repeat-a-string/Go/repeat-a-string-1.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
fmt.Println(strings.Repeat("ha", 5)) // ==> "hahahahaha"
|
||||
1
Task/Repeat-a-string/Go/repeat-a-string-2.go
Normal file
1
Task/Repeat-a-string/Go/repeat-a-string-2.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
fmt.Println(strings.Repeat(string('h'), 5)) // prints hhhhh
|
||||
1
Task/Repeat-a-string/Groovy/repeat-a-string.groovy
Normal file
1
Task/Repeat-a-string/Groovy/repeat-a-string.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
println 'ha' * 5
|
||||
1
Task/Repeat-a-string/Haskell/repeat-a-string-1.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-1.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
concat $ replicate 5 "ha"
|
||||
1
Task/Repeat-a-string/Haskell/repeat-a-string-2.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1..5] >> "ha"
|
||||
1
Task/Repeat-a-string/Haskell/repeat-a-string-3.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-3.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
cycle "ha"
|
||||
1
Task/Repeat-a-string/Haskell/repeat-a-string-4.hs
Normal file
1
Task/Repeat-a-string/Haskell/repeat-a-string-4.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
replicate 5 '*'
|
||||
3
Task/Repeat-a-string/HicEst/repeat-a-string.hicest
Normal file
3
Task/Repeat-a-string/HicEst/repeat-a-string.hicest
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
CHARACTER out*20
|
||||
|
||||
EDIT(Text=out, Insert="ha", DO=5)
|
||||
3
Task/Repeat-a-string/Icon/repeat-a-string-1.icon
Normal file
3
Task/Repeat-a-string/Icon/repeat-a-string-1.icon
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
procedure main(args)
|
||||
write(repl(integer(!args) | 5))
|
||||
end
|
||||
4
Task/Repeat-a-string/Icon/repeat-a-string-2.icon
Normal file
4
Task/Repeat-a-string/Icon/repeat-a-string-2.icon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
procedure repl(s, n)
|
||||
every (ns := "") ||:= |s\(0 <= n)
|
||||
return ns
|
||||
end
|
||||
11
Task/Repeat-a-string/Inform-7/repeat-a-string.inf
Normal file
11
Task/Repeat-a-string/Inform-7/repeat-a-string.inf
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Home is a room.
|
||||
|
||||
To decide which indexed text is (T - indexed text) repeated (N - number) times:
|
||||
let temp be indexed text;
|
||||
repeat with M running from 1 to N:
|
||||
let temp be "[temp][T]";
|
||||
decide on temp.
|
||||
|
||||
When play begins:
|
||||
say "ha" repeated 5 times;
|
||||
end the story.
|
||||
8
Task/Repeat-a-string/J/repeat-a-string.j
Normal file
8
Task/Repeat-a-string/J/repeat-a-string.j
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
5 # '*' NB. repeat each item 5 times
|
||||
*****
|
||||
5 # 'ha' NB. repeat each item 5 times
|
||||
hhhhhaaaaa
|
||||
5 ((* #) $ ]) 'ha' NB. repeat array 5 times
|
||||
hahahahaha
|
||||
5 ;@# < 'ha' NB. boxing is used to treat the array as a whole
|
||||
hahahahaha
|
||||
9
Task/Repeat-a-string/Java/repeat-a-string-1.java
Normal file
9
Task/Repeat-a-string/Java/repeat-a-string-1.java
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
public static String repeat(String str, int times){
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for(int i = 0;i < times;i++) ret.append(str);
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
System.out.println(repeat("ha", 5));
|
||||
}
|
||||
3
Task/Repeat-a-string/Java/repeat-a-string-2.java
Normal file
3
Task/Repeat-a-string/Java/repeat-a-string-2.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public static String repeat(String str, int times){
|
||||
return new String(new char[times]).replace("\0", str);
|
||||
}
|
||||
5
Task/Repeat-a-string/JavaScript/repeat-a-string.js
Normal file
5
Task/Repeat-a-string/JavaScript/repeat-a-string.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
String.prototype.repeat = function(n) {
|
||||
return new Array(1 + n).join(this);
|
||||
}
|
||||
|
||||
alert("ha".repeat(5)); // hahahahaha
|
||||
2
Task/Repeat-a-string/Julia/repeat-a-string.julia
Normal file
2
Task/Repeat-a-string/Julia/repeat-a-string.julia
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"ha"^5
|
||||
'*'^5
|
||||
5
Task/Repeat-a-string/K/repeat-a-string.k
Normal file
5
Task/Repeat-a-string/K/repeat-a-string.k
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
,/5#,"ha"
|
||||
"hahahahaha"
|
||||
|
||||
5#"*"
|
||||
"*****"
|
||||
12
Task/Repeat-a-string/Liberty-BASIC/repeat-a-string.liberty
Normal file
12
Task/Repeat-a-string/Liberty-BASIC/repeat-a-string.liberty
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
a$ ="ha "
|
||||
print StringRepeat$( a$, 5)
|
||||
|
||||
end
|
||||
|
||||
function StringRepeat$( in$, n)
|
||||
o$ =""
|
||||
for i =1 to n
|
||||
o$ =o$ +in$
|
||||
next i
|
||||
StringRepeat$ =o$
|
||||
end function
|
||||
4
Task/Repeat-a-string/Logo/repeat-a-string-1.logo
Normal file
4
Task/Repeat-a-string/Logo/repeat-a-string-1.logo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
to copies :n :thing [:acc "||]
|
||||
if :n = 0 [output :acc]
|
||||
output (copies :n-1 :thing combine :acc :thing)
|
||||
end
|
||||
1
Task/Repeat-a-string/Logo/repeat-a-string-2.logo
Normal file
1
Task/Repeat-a-string/Logo/repeat-a-string-2.logo
Normal file
|
|
@ -0,0 +1 @@
|
|||
show cascade 5 [combine "ha ?] "|| ; hahahahaha
|
||||
6
Task/Repeat-a-string/Logo/repeat-a-string-3.logo
Normal file
6
Task/Repeat-a-string/Logo/repeat-a-string-3.logo
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
to copies :n :thing :acc
|
||||
if :n = 0 [output :acc]
|
||||
output (copies :n-1 :thing combine :acc :thing)
|
||||
end
|
||||
|
||||
print copies 5 "ha "||
|
||||
1
Task/Repeat-a-string/Lua/repeat-a-string-1.lua
Normal file
1
Task/Repeat-a-string/Lua/repeat-a-string-1.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
function repeats(s, n) return n > 0 and s .. repeat(s, n-1) or "" end
|
||||
1
Task/Repeat-a-string/Lua/repeat-a-string-2.lua
Normal file
1
Task/Repeat-a-string/Lua/repeat-a-string-2.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
string.rep(s,n)
|
||||
3
Task/Repeat-a-string/MATLAB/repeat-a-string.m
Normal file
3
Task/Repeat-a-string/MATLAB/repeat-a-string.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function S = repeat(s , n)
|
||||
S = repmat(s , [1,n]) ;
|
||||
return
|
||||
9
Task/Repeat-a-string/MUMPS/repeat-a-string-1.mumps
Normal file
9
Task/Repeat-a-string/MUMPS/repeat-a-string-1.mumps
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
RPTSTR(S,N)
|
||||
;Repeat a string S for N times
|
||||
NEW I
|
||||
FOR I=1:1:N WRITE S
|
||||
KILL I
|
||||
QUIT
|
||||
RPTSTR1(S,N) ;Functionally equivalent, but denser to read
|
||||
F I=1:1:N W S
|
||||
Q
|
||||
3
Task/Repeat-a-string/MUMPS/repeat-a-string-2.mumps
Normal file
3
Task/Repeat-a-string/MUMPS/repeat-a-string-2.mumps
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
;Even better (more terse)
|
||||
S x="",$P(x,"-",10)="-"
|
||||
W x
|
||||
7
Task/Repeat-a-string/Maple/repeat-a-string-1.maple
Normal file
7
Task/Repeat-a-string/Maple/repeat-a-string-1.maple
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
> use StringTools in
|
||||
> Repeat( "abc", 10 ); # repeat an arbitrary string
|
||||
> Fill( "x", 20 ) # repeat a character
|
||||
> end use;
|
||||
"abcabcabcabcabcabcabcabcabcabc"
|
||||
|
||||
"xxxxxxxxxxxxxxxxxxxx"
|
||||
5
Task/Repeat-a-string/Maple/repeat-a-string-2.maple
Normal file
5
Task/Repeat-a-string/Maple/repeat-a-string-2.maple
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
> cat( "abc" $ 10 );
|
||||
"abcabcabcabcabcabcabcabcabcabc"
|
||||
|
||||
> cat( seq( "abc", i = 1 .. 10 ) );
|
||||
"abcabcabcabcabcabcabcabcabcabc"
|
||||
3
Task/Repeat-a-string/Maple/repeat-a-string-3.maple
Normal file
3
Task/Repeat-a-string/Maple/repeat-a-string-3.maple
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> s := "":
|
||||
> to 10 do s := cat( s, "abc" ) end: s;
|
||||
"abcabcabcabcabcabcabcabcabcabc"
|
||||
8
Task/Repeat-a-string/Mathematica/repeat-a-string.math
Normal file
8
Task/Repeat-a-string/Mathematica/repeat-a-string.math
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(* solution 1 *)
|
||||
rep[n_Integer,s_String]:=Apply[StringJoin,ConstantArray[s,{n}]]
|
||||
|
||||
(* solution 2 -- @@ is the infix form of Apply[] *)
|
||||
rep[n_Integer,s_String]:=StringJoin@@Table[s,{n}]
|
||||
|
||||
(* solution 3 -- demonstrating another of the large number of looping constructs available *)
|
||||
rep[n_Integer,s_String]:=Nest[StringJoin[s, #] &,s,n-1]
|
||||
5
Task/Repeat-a-string/Maxima/repeat-a-string.maxima
Normal file
5
Task/Repeat-a-string/Maxima/repeat-a-string.maxima
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
"$*"(s, n) := apply(sconcat, makelist(s, n))$
|
||||
infix("$*")$
|
||||
|
||||
"abc" $* 5;
|
||||
/* "abcabcabcabcabc" */
|
||||
26
Task/Repeat-a-string/Mercury/repeat-a-string.mercury
Normal file
26
Task/Repeat-a-string/Mercury/repeat-a-string.mercury
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
:- module repeat.
|
||||
:- interface.
|
||||
:- import_module string, char, int.
|
||||
|
||||
:- func repeat_char(char, int) = string.
|
||||
:- func repeat(string, int) = string.
|
||||
|
||||
:- implementation.
|
||||
:- import_module stream, stream.string_writer, string.builder.
|
||||
|
||||
repeat_char(C, N) = string.duplicate_char(C, N).
|
||||
|
||||
repeat(String, Count) = Repeated :-
|
||||
S0 = string.builder.init,
|
||||
Repeated = string.builder.to_string(S),
|
||||
printn(string.builder.handle, Count, String, S0, S).
|
||||
|
||||
:- pred printn(Stream, int, string, State, State)
|
||||
<= (stream.writer(Stream, string, State),
|
||||
stream.writer(Stream, character, State)).
|
||||
:- mode printn(in, in, in, di, uo) is det.
|
||||
printn(Stream, N, String, !S) :-
|
||||
( N > 0 ->
|
||||
print(Stream, String, !S),
|
||||
printn(Stream, N - 1, String, !S)
|
||||
; true ).
|
||||
7
Task/Repeat-a-string/Mirah/repeat-a-string.mirah
Normal file
7
Task/Repeat-a-string/Mirah/repeat-a-string.mirah
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
x = StringBuilder.new
|
||||
|
||||
5.times do
|
||||
x.append "ha"
|
||||
end
|
||||
|
||||
puts x # ==> "hahahahaha"
|
||||
3
Task/Repeat-a-string/NetRexx/repeat-a-string-1.netrexx
Normal file
3
Task/Repeat-a-string/NetRexx/repeat-a-string-1.netrexx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/* NetRexx */
|
||||
|
||||
ha5 = 'ha'.copies(5)
|
||||
12
Task/Repeat-a-string/NetRexx/repeat-a-string-2.netrexx
Normal file
12
Task/Repeat-a-string/NetRexx/repeat-a-string-2.netrexx
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/* NetRexx */
|
||||
sampleStr = 'ha' -- string to duplicate
|
||||
say ' COPIES:' sampleStr.copies(5)
|
||||
say 'CHANGESTR:' '.....'.changestr('.', sampleStr)
|
||||
|
||||
sampleChr = '*' -- character to duplicate
|
||||
say ' LEFT:' sampleChr.left(5, sampleChr)
|
||||
say ' RIGHT:' sampleChr.right(5, sampleChr)
|
||||
say ' CENTRE:' sampleChr.centre(5, sampleChr)
|
||||
say ' OVERLAY:' sampleChr.overlay(sampleChr, 1, 5, sampleChr)
|
||||
say ' SUBSTR:' ''.substr(1, 5, sampleChr)
|
||||
say 'TRANSLATE:' '.....'.translate(sampleChr, '.')
|
||||
1
Task/Repeat-a-string/NewLISP/repeat-a-string.newlisp
Normal file
1
Task/Repeat-a-string/NewLISP/repeat-a-string.newlisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(dup "ha" 5)
|
||||
8
Task/Repeat-a-string/OCaml/repeat-a-string-1.ocaml
Normal file
8
Task/Repeat-a-string/OCaml/repeat-a-string-1.ocaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let string_repeat s n =
|
||||
let len = String.length s in
|
||||
let res = String.create(n * len) in
|
||||
for i = 0 to pred n do
|
||||
String.blit s 0 res (i * len) len;
|
||||
done;
|
||||
(res)
|
||||
;;
|
||||
2
Task/Repeat-a-string/OCaml/repeat-a-string-2.ocaml
Normal file
2
Task/Repeat-a-string/OCaml/repeat-a-string-2.ocaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# string_repeat "Hiuoa" 3 ;;
|
||||
- : string = "HiuoaHiuoaHiuoa"
|
||||
3
Task/Repeat-a-string/OCaml/repeat-a-string-3.ocaml
Normal file
3
Task/Repeat-a-string/OCaml/repeat-a-string-3.ocaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
let string_repeat s n =
|
||||
String.concat "" (Array.to_list (Array.make n s))
|
||||
;;
|
||||
3
Task/Repeat-a-string/OCaml/repeat-a-string-4.ocaml
Normal file
3
Task/Repeat-a-string/OCaml/repeat-a-string-4.ocaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
let string_repeat s n =
|
||||
Array.fold_left (^) "" (Array.make n s)
|
||||
;;
|
||||
1
Task/Repeat-a-string/OCaml/repeat-a-string-5.ocaml
Normal file
1
Task/Repeat-a-string/OCaml/repeat-a-string-5.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
String.make 5 '*'
|
||||
16
Task/Repeat-a-string/Objeck/repeat-a-string.objeck
Normal file
16
Task/Repeat-a-string/Objeck/repeat-a-string.objeck
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
bundle Default {
|
||||
class Repeat {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
Repeat("ha", 5)->PrintLine();
|
||||
}
|
||||
|
||||
function : Repeat(string : String, max : Int) ~ String {
|
||||
repeat : String := String->New();
|
||||
for(i := 0; i < max; i += 1;) {
|
||||
repeat->Append(string);
|
||||
};
|
||||
|
||||
return repeat;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Task/Repeat-a-string/Objective-C/repeat-a-string-1.m
Normal file
9
Task/Repeat-a-string/Objective-C/repeat-a-string-1.m
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
@interface NSString (RosettaCodeAddition)
|
||||
- (NSString *) repeatStringByNumberOfTimes: (NSUInteger) times;
|
||||
@end
|
||||
|
||||
@implementation NSString (RosettaCodeAddition)
|
||||
- (NSString *) repeatStringByNumberOfTimes: (NSUInteger) times {
|
||||
return [@"" stringByPaddingToLength:[self length]*times withString:self startingAtIndex:0];
|
||||
}
|
||||
@end
|
||||
6
Task/Repeat-a-string/Objective-C/repeat-a-string-2.m
Normal file
6
Task/Repeat-a-string/Objective-C/repeat-a-string-2.m
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// Instantiate an NSString by sending an NSString literal our new
|
||||
// -repeatByNumberOfTimes: selector.
|
||||
NSString *aString = [@"ha" repeatStringByNumberOfTimes:5];
|
||||
|
||||
// Display the NSString.
|
||||
NSLog(@"%@", aString);
|
||||
|
|
@ -0,0 +1 @@
|
|||
MESSAGE FILL( "ha", 5 ) VIEW-AS ALERT-BOX.
|
||||
18
Task/Repeat-a-string/OxygenBasic/repeat-a-string.oxy
Normal file
18
Task/Repeat-a-string/OxygenBasic/repeat-a-string.oxy
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
'REPEATING A CHARACTER
|
||||
|
||||
print string 10,"A" 'result AAAAAAAAAA
|
||||
|
||||
'REPEATING A STRING
|
||||
|
||||
function RepeatString(string s,sys n) as string
|
||||
sys i, le=len s
|
||||
if le=0 then exit function
|
||||
n*=le
|
||||
function=nuls n
|
||||
'
|
||||
for i=1 to n step le
|
||||
mid function,i,s
|
||||
next
|
||||
end function
|
||||
|
||||
print RepeatString "ABC",3 'result ABCABCABC
|
||||
10
Task/Repeat-a-string/Oz/repeat-a-string.oz
Normal file
10
Task/Repeat-a-string/Oz/repeat-a-string.oz
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
declare
|
||||
fun {Repeat Xs N}
|
||||
if N > 0 then
|
||||
{Append Xs {Repeat Xs N-1}}
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
in
|
||||
{System.showInfo {Repeat "Ha" 5}}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue