Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,2 @@
"ha" 5 s:*
. cr

View file

@ -0,0 +1,3 @@
shared void repeatAString() {
print("ha".repeat(5));
}

View file

@ -0,0 +1,5 @@
IMPORT STD; //Imports the Standard Library
STRING MyBaseString := 'abc';
RepeatedString := STD.Str.Repeat(MyBaseString,3);
RepeatedString; //returns 'abcabcabc'

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

View 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

View file

@ -0,0 +1 @@
(S.concat (take 5 (repeat1 "ha")))

View 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

View file

@ -0,0 +1 @@
? Replicate( "Ha", 5 )

View 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

View file

@ -0,0 +1 @@
(string:copies '"ha" 5)

View file

@ -0,0 +1 @@
'ha'*5 // hahahahaha

View file

@ -0,0 +1 @@
loop(5) => {^ 'ha' ^} // hahahahaha

View 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

View file

@ -0,0 +1,2 @@
put rep("ha", 5)
-- "hahahahaha"

View file

@ -0,0 +1,2 @@
put bytearray(5, chartonum("*")).readRawString(5)
-- "*****"

View 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

View file

@ -0,0 +1,2 @@
var s := "ha " * 5
traceln(s)

View file

@ -0,0 +1,2 @@
import strutils
repeatStr(5, "ha")

View file

@ -0,0 +1 @@
StringBuffer new "abcd" <<n(5)

View file

@ -0,0 +1,2 @@
?repeat('*',5)
?join(repeat("ha",5),"")

View file

@ -0,0 +1 @@
Copy("ha" , 5) # ==> "hahahahaha"

View file

@ -0,0 +1 @@
'ha' * 5; # ==> 'hahahahaha'

View file

@ -0,0 +1,2 @@
spn:3> repeat("na", 8) .. " Batman!"
= nananananananana Batman!

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

View file

@ -0,0 +1 @@
String(count:5, repeatedValue:"*" as Character)

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

View file

@ -0,0 +1 @@
? REPLICATE("HO", 3)

View file

@ -0,0 +1,7 @@
def (s * n) :case (string? s)
with outstring
repeat n
pr s
("ha" * 5)
=> "hahahahaha"

View file

@ -0,0 +1 @@
@join "" @rep 5 "ha" ; returns "hahahahaha"

View file

@ -0,0 +1 @@
^(\@join "" @rep)

View file

@ -0,0 +1 @@
"a " * 3' # => "a a a "