Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
46
Task/Rep-string/Picat/rep-string.picat
Normal file
46
Task/Rep-string/Picat/rep-string.picat
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
go =>
|
||||
Strings = [
|
||||
"1001110011", % 10011
|
||||
"1110111011", % 1110
|
||||
"0010010010", % 001
|
||||
"1010101010", % 1010
|
||||
"1111111111", % 11111
|
||||
"0100101101", % no solution
|
||||
"0100100", % 010
|
||||
"101", % no solution
|
||||
"11", % 1
|
||||
"00", % 0
|
||||
"1", % no solution
|
||||
"", % no solution
|
||||
"123123123123123", % 123123
|
||||
"12312312312312", % 123123
|
||||
"123123123123124", % no solution
|
||||
"abcabcdabcabcdabc", % abcabcd
|
||||
[1,2,3,4,1,2,3,4,1,2,3] % 1,2,3,4
|
||||
|
||||
],
|
||||
foreach(S in Strings)
|
||||
printf("%w: ", S),
|
||||
if maxrep(S,Substr,N) then
|
||||
println([substr=Substr,n=N])
|
||||
else
|
||||
println("no solution")
|
||||
end
|
||||
end,
|
||||
nl.
|
||||
|
||||
% the largest repeating substring
|
||||
maxrep(S,Substr,N) =>
|
||||
maxof(rep(S,Substr,N),N).
|
||||
|
||||
rep(S,Substr,N) =>
|
||||
between(1,S.length div 2, N),
|
||||
Len = S.length,
|
||||
Len2 = Len - (Len mod N),
|
||||
Substr = slice(S,1,N),
|
||||
% count the number of proper slices
|
||||
SS = [1 : I in 1..N..Len2, slice(S,I,I+N-1) = Substr],
|
||||
SS.length = Len div N,
|
||||
% the last (truncated) slice (or []) must be a substring of Substr
|
||||
Rest = slice(S,Len2+1,Len),
|
||||
find(Substr,Rest,1,_).
|
||||
Loading…
Add table
Add a link
Reference in a new issue