Originally Posted by

**fifthrapiers** 2.) Using both the even algorithm and the one you come up with in 1, find all of the even and odd palindromes of the following string: c b a a b a

The following functions implement the algorithms (as far as I can tell)

(note I am working with numerical arrays rather than strings as it is

easier to implement quickly)

(code written so quickly comes with no guarantee of correctness )

Code:

function Epalind(s)
##
## find even palindromes in s
##
##
n=length(s);
sr=s(n:-1:1);
for q=1 to n
mxk=min(n-q,q-1);
for k=1 to mxk
s1=s(q+1:q+k);
s2=sr(n-q+1:n-q+k);
if prod(s1==s2)==1
s(q-k+1:q+k)
endif
end
end
return 0
endfunction
..======================================
function Opalind(s)
##
## fid odd palindromes in s
##
n=length(s);
sr=s(n:-1:1);
for q=1 to n
mxk=min(n-q,q-1);
for k=1 to mxk
s1=s(q+1:q+k);
s2=sr(n-q+2:n-q+k+1);
if prod(s1==s2)==1
s(q-k:q+k)
endif
end
end
return 0
endfunction

Results are:

Code:

>
>s=[3,2,1,1,2,1];
>Epalind(s);
1 1
2 1 1 2
>
>
>Opalind(s);
1 2 1
>

RonL