September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
38
Task/Rep-string/Phix/rep-string.phix
Normal file
38
Task/Rep-string/Phix/rep-string.phix
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
function list_reps(string r)
|
||||
sequence replist = {}
|
||||
integer n = length(r)
|
||||
for m=1 to floor(n/2) do
|
||||
string s = r[1..m]
|
||||
if join(repeat(s,floor(n/m)+1),"")[1..n]=r then
|
||||
replist = append(replist,s)
|
||||
end if
|
||||
end for
|
||||
return replist
|
||||
end function
|
||||
|
||||
constant tests = {"1001110011",
|
||||
"1110111011",
|
||||
"0010010010",
|
||||
"1010101010",
|
||||
"1111111111",
|
||||
"0100101101",
|
||||
"0100100",
|
||||
"101",
|
||||
"11",
|
||||
"00",
|
||||
"1"}
|
||||
|
||||
for i=1 to length(tests) do
|
||||
printf(1,"%s\n",{tests[i]})
|
||||
sequence replist = list_reps(tests[i])
|
||||
if length(replist)=0 then
|
||||
printf(1,"not a rep-string.\n")
|
||||
else
|
||||
for j=1 to length(replist) do
|
||||
string rj = replist[j],
|
||||
pad = repeat(' ',length(rj))
|
||||
printf(1,"%s%s\n",{pad,rj})
|
||||
end for
|
||||
end if
|
||||
printf(1,"\n")
|
||||
end for
|
||||
Loading…
Add table
Add a link
Reference in a new issue