33 lines
507 B
Plaintext
33 lines
507 B
Plaintext
func rep(s) {
|
|
var x = s.Length() / 2
|
|
while x > 0 {
|
|
if s.StartsWith(s.Substring(x)) {
|
|
return x
|
|
}
|
|
x -= 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
let m = [
|
|
"1001110011",
|
|
"1110111011",
|
|
"0010010010",
|
|
"1010101010",
|
|
"1111111111",
|
|
"0100101101",
|
|
"0100100",
|
|
"101",
|
|
"11",
|
|
"00",
|
|
"1"
|
|
]
|
|
|
|
for s in m {
|
|
if (rep(s) is n) && n > 0 {
|
|
print("\(s) \(n) rep-string \(s.Substring(n))")
|
|
} else {
|
|
print("\(s) not a rep-string")
|
|
}
|
|
}
|