Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
2
Task/Repeat-a-string/8th/repeat-a-string.8th
Normal file
2
Task/Repeat-a-string/8th/repeat-a-string.8th
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"ha" 5 s:*
|
||||
. cr
|
||||
3
Task/Repeat-a-string/Ceylon/repeat-a-string.ceylon
Normal file
3
Task/Repeat-a-string/Ceylon/repeat-a-string.ceylon
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
shared void repeatAString() {
|
||||
print("ha".repeat(5));
|
||||
}
|
||||
5
Task/Repeat-a-string/ECL/repeat-a-string-1.ecl
Normal file
5
Task/Repeat-a-string/ECL/repeat-a-string-1.ecl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
IMPORT STD; //Imports the Standard Library
|
||||
|
||||
STRING MyBaseString := 'abc';
|
||||
RepeatedString := STD.Str.Repeat(MyBaseString,3);
|
||||
RepeatedString; //returns 'abcabcabc'
|
||||
9
Task/Repeat-a-string/ECL/repeat-a-string-2.ecl
Normal file
9
Task/Repeat-a-string/ECL/repeat-a-string-2.ecl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
RepeatString(STRING InStr, INTEGER Cnt) := FUNCTION
|
||||
rec := {STRING Str};
|
||||
ds := DATASET(Cnt,TRANSFORM(rec,SELF.Str := InStr));
|
||||
res := ITERATE(ds,TRANSFORM(rec,SELF.Str := LEFT.Str + RIGHT.Str));
|
||||
RETURN Res[Cnt].Str;
|
||||
END;
|
||||
|
||||
RepeatString('ha',3);
|
||||
RepeatString('Who',2);
|
||||
7
Task/Repeat-a-string/ERRE/repeat-a-string.erre
Normal file
7
Task/Repeat-a-string/ERRE/repeat-a-string.erre
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
PROCEDURE REPEAT_STRING(S$,N%->REP$)
|
||||
LOCAL I%
|
||||
REP$=""
|
||||
FOR I%=1 TO N% DO
|
||||
REP$=REP$+S$
|
||||
END FOR
|
||||
END PROCEDURE
|
||||
1
Task/Repeat-a-string/Egison/repeat-a-string.egison
Normal file
1
Task/Repeat-a-string/Egison/repeat-a-string.egison
Normal file
|
|
@ -0,0 +1 @@
|
|||
(S.concat (take 5 (repeat1 "ha")))
|
||||
29
Task/Repeat-a-string/FreeBASIC/repeat-a-string.freebasic
Normal file
29
Task/Repeat-a-string/FreeBASIC/repeat-a-string.freebasic
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
' A character is essentially a string of length 1 in FB though there is a built-in function, String,
|
||||
' which creates a string by repeating a character a given number of times.
|
||||
|
||||
' To avoid repeated concatenation (a slow operation) when the string to be repeated has a length
|
||||
' greater than one, we instead create a buffer of the required size and then fill that.
|
||||
|
||||
Function repeat(s As String, n As Integer) As String
|
||||
If n < 1 Then Return ""
|
||||
If n = 1 Then Return s
|
||||
Var size = Len(s)
|
||||
If size = 0 Then Return s ' empty string
|
||||
If size = 1 Then Return String(n, s[0]) ' repeated single character
|
||||
Var buffer = Space(size * n) 'create buffer for size > 1
|
||||
For i As Integer = 0 To n - 1
|
||||
For j As Integer = 0 To size - 1
|
||||
buffer[i * size + j] = s[j]
|
||||
Next j
|
||||
Next i
|
||||
Return buffer
|
||||
End Function
|
||||
|
||||
Print repeat("rosetta", 1)
|
||||
Print repeat("ha", 5)
|
||||
Print repeat("*", 5)
|
||||
Print
|
||||
Print "Press any key to quit program"
|
||||
Sleep
|
||||
1
Task/Repeat-a-string/Harbour/repeat-a-string.harbour
Normal file
1
Task/Repeat-a-string/Harbour/repeat-a-string.harbour
Normal file
|
|
@ -0,0 +1 @@
|
|||
? Replicate( "Ha", 5 )
|
||||
7
Task/Repeat-a-string/Idris/repeat-a-string.idris
Normal file
7
Task/Repeat-a-string/Idris/repeat-a-string.idris
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
strRepeat : Nat -> String -> String
|
||||
strRepeat Z s = ""
|
||||
strRepeat (S n) s = s ++ strRepeat n s
|
||||
|
||||
chrRepeat : Nat -> Char -> String
|
||||
chrRepeat Z c = ""
|
||||
chrRepeat (S n) c = strCons c $ chrRepeat n c
|
||||
1
Task/Repeat-a-string/LFE/repeat-a-string.lfe
Normal file
1
Task/Repeat-a-string/LFE/repeat-a-string.lfe
Normal file
|
|
@ -0,0 +1 @@
|
|||
(string:copies '"ha" 5)
|
||||
1
Task/Repeat-a-string/Lasso/repeat-a-string-1.lasso
Normal file
1
Task/Repeat-a-string/Lasso/repeat-a-string-1.lasso
Normal file
|
|
@ -0,0 +1 @@
|
|||
'ha'*5 // hahahahaha
|
||||
1
Task/Repeat-a-string/Lasso/repeat-a-string-2.lasso
Normal file
1
Task/Repeat-a-string/Lasso/repeat-a-string-2.lasso
Normal file
|
|
@ -0,0 +1 @@
|
|||
loop(5) => {^ 'ha' ^} // hahahahaha
|
||||
7
Task/Repeat-a-string/Lingo/repeat-a-string-1.lingo
Normal file
7
Task/Repeat-a-string/Lingo/repeat-a-string-1.lingo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
on rep (str, n)
|
||||
res = ""
|
||||
repeat with i = 1 to n
|
||||
put str after res
|
||||
end repeat
|
||||
return res
|
||||
end
|
||||
2
Task/Repeat-a-string/Lingo/repeat-a-string-2.lingo
Normal file
2
Task/Repeat-a-string/Lingo/repeat-a-string-2.lingo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
put rep("ha", 5)
|
||||
-- "hahahahaha"
|
||||
2
Task/Repeat-a-string/Lingo/repeat-a-string-3.lingo
Normal file
2
Task/Repeat-a-string/Lingo/repeat-a-string-3.lingo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
put bytearray(5, chartonum("*")).readRawString(5)
|
||||
-- "*****"
|
||||
10
Task/Repeat-a-string/LiveCode/repeat-a-string.livecode
Normal file
10
Task/Repeat-a-string/LiveCode/repeat-a-string.livecode
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
on mouseUp
|
||||
put repeatString("ha", 5)
|
||||
end mouseUp
|
||||
|
||||
function repeatString str n
|
||||
repeat n times
|
||||
put str after t
|
||||
end repeat
|
||||
return t
|
||||
end repeatString
|
||||
2
Task/Repeat-a-string/Monte/repeat-a-string.monte
Normal file
2
Task/Repeat-a-string/Monte/repeat-a-string.monte
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var s := "ha " * 5
|
||||
traceln(s)
|
||||
2
Task/Repeat-a-string/Nim/repeat-a-string.nim
Normal file
2
Task/Repeat-a-string/Nim/repeat-a-string.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import strutils
|
||||
repeatStr(5, "ha")
|
||||
1
Task/Repeat-a-string/Oforth/repeat-a-string.oforth
Normal file
1
Task/Repeat-a-string/Oforth/repeat-a-string.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
StringBuffer new "abcd" <<n(5)
|
||||
2
Task/Repeat-a-string/Phix/repeat-a-string.phix
Normal file
2
Task/Repeat-a-string/Phix/repeat-a-string.phix
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
?repeat('*',5)
|
||||
?join(repeat("ha",5),"")
|
||||
1
Task/Repeat-a-string/Ring/repeat-a-string.ring
Normal file
1
Task/Repeat-a-string/Ring/repeat-a-string.ring
Normal file
|
|
@ -0,0 +1 @@
|
|||
Copy("ha" , 5) # ==> "hahahahaha"
|
||||
1
Task/Repeat-a-string/Sidef/repeat-a-string.sidef
Normal file
1
Task/Repeat-a-string/Sidef/repeat-a-string.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
'ha' * 5; # ==> 'hahahahaha'
|
||||
2
Task/Repeat-a-string/Sparkling/repeat-a-string.sparkling
Normal file
2
Task/Repeat-a-string/Sparkling/repeat-a-string.sparkling
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
spn:3> repeat("na", 8) .. " Batman!"
|
||||
= nananananananana Batman!
|
||||
19
Task/Repeat-a-string/Swift/repeat-a-string-1.swift
Normal file
19
Task/Repeat-a-string/Swift/repeat-a-string-1.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
extension String {
|
||||
// Slower version
|
||||
func repeatString(n: Int) -> String {
|
||||
return Array(count: n, repeatedValue: self).joinWithSeparator("")
|
||||
}
|
||||
|
||||
// Faster version
|
||||
// benchmarked with a 1000 characters and 100 repeats the fast version is approx 500 000 times faster :-)
|
||||
func repeatString2(n:Int) -> String {
|
||||
var result = self
|
||||
for _ in 1 ..< n {
|
||||
result.appendContentsOf(self) // Note that String.appendContentsOf is up to 10 times faster than "result += self"
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
print( "ha".repeatString(5) )
|
||||
print( "he".repeatString2(5) )
|
||||
1
Task/Repeat-a-string/Swift/repeat-a-string-2.swift
Normal file
1
Task/Repeat-a-string/Swift/repeat-a-string-2.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
String(count:5, repeatedValue:"*" as Character)
|
||||
19
Task/Repeat-a-string/Swift/repeat-a-string-3.swift
Normal file
19
Task/Repeat-a-string/Swift/repeat-a-string-3.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
extension String {
|
||||
func repeatBiterative(count: Int) -> String {
|
||||
var reduceCount = count
|
||||
var result = ""
|
||||
var doubled = self
|
||||
while reduceCount != 0 {
|
||||
if reduceCount & 1 == 1 {
|
||||
result.appendContentsOf(doubled)
|
||||
}
|
||||
reduceCount >>= 1
|
||||
if reduceCount != 0 {
|
||||
doubled.appendContentsOf(doubled)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
"He".repeatBiterative(5)
|
||||
|
|
@ -0,0 +1 @@
|
|||
? REPLICATE("HO", 3)
|
||||
7
Task/Repeat-a-string/Wart/repeat-a-string.wart
Normal file
7
Task/Repeat-a-string/Wart/repeat-a-string.wart
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def (s * n) :case (string? s)
|
||||
with outstring
|
||||
repeat n
|
||||
pr s
|
||||
|
||||
("ha" * 5)
|
||||
=> "hahahahaha"
|
||||
1
Task/Repeat-a-string/Wortel/repeat-a-string-1.wortel
Normal file
1
Task/Repeat-a-string/Wortel/repeat-a-string-1.wortel
Normal file
|
|
@ -0,0 +1 @@
|
|||
@join "" @rep 5 "ha" ; returns "hahahahaha"
|
||||
1
Task/Repeat-a-string/Wortel/repeat-a-string-2.wortel
Normal file
1
Task/Repeat-a-string/Wortel/repeat-a-string-2.wortel
Normal file
|
|
@ -0,0 +1 @@
|
|||
^(\@join "" @rep)
|
||||
1
Task/Repeat-a-string/jq/repeat-a-string.jq
Normal file
1
Task/Repeat-a-string/jq/repeat-a-string.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"a " * 3' # => "a a a "
|
||||
Loading…
Add table
Add a link
Reference in a new issue