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