Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1 @@
print(String(repeating:"*", count: 5))

View file

@ -0,0 +1,5 @@
func * (left:String, right:Int) -> String {
return String(repeating:left, count:right)
}
print ("HA" * 5)

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)