Rep-string: Difference between revisions

Added Dyalect programming language
(Add Swift)
(Added Dyalect programming language)
Line 781:
0 0
1 (no repeat)</pre>
 
=={{header|Dyalect}}==
 
{{trans|Go}}
 
<lang dyalect>func rep(s) {
var x = s.len() / 2
while x > 0 {
if s.startsWith(s.sub(x)) {
return x
}
x -= 1
}
return 0
}
const 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.sub(n))")
} else {
print("\(s) not a rep-string")
}
}</lang>
 
{{out}}
 
<pre>1001110011 5 rep-string 10011
1110111011 4 rep-string 111011
0010010010 3 rep-string 0010010
1010101010 4 rep-string 101010
1111111111 5 rep-string 11111
0100101101 not a rep-string
0100100 3 rep-string 0100
101 not a rep-string
11 1 rep-string 1
00 1 rep-string 0
1 not a rep-string
Time taken: 00:00:00.0764278</pre>
 
=={{header|EchoLisp}}==
Anonymous user