Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Rep-string/Crystal/rep-string.crystal
Normal file
31
Task/Rep-string/Crystal/rep-string.crystal
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
def rep(s : String) : Int32
|
||||
x = s.size // 2
|
||||
|
||||
while x > 0
|
||||
return x if s.starts_with? s[x..]
|
||||
x -= 1
|
||||
end
|
||||
|
||||
0
|
||||
end
|
||||
|
||||
def main
|
||||
%w(
|
||||
1001110011
|
||||
1110111011
|
||||
0010010010
|
||||
1010101010
|
||||
1111111111
|
||||
0100101101
|
||||
0100100
|
||||
101
|
||||
11
|
||||
00
|
||||
1
|
||||
).each do |s|
|
||||
n = rep s
|
||||
puts n > 0 ? "\"#{s}\" #{n} rep-string \"#{s[..(n - 1)]}\"" : "\"#{s}\" not a rep-string"
|
||||
end
|
||||
end
|
||||
|
||||
main
|
||||
Loading…
Add table
Add a link
Reference in a new issue