TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Bartolini, Antony (ABARTOLI)" <[log in to unmask]>
Reply To:
Bartolini, Antony (ABARTOLI)
Date:
Thu, 20 Apr 2000 16:21:45 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (37 lines)
It seems to me that this will return true for
any string presented. It calls itself with a
smaller and smaller slice of the string until
it makes the <=1 requirement and then returns
a boolean true all the way back up. I put it
into a small example test program and thats
what I seem to get. Am I missing something?

Thanks,

Tony Bartolini ([log in to unmask])

-----Original Message-----
From: Bill Taylor [mailto:[log in to unmask]]
Sent: Thursday, April 20, 2000 3:30 PM
To: [log in to unmask]
Subject: Re: [Off topic] palindromes


An easier to implement alternative is:

A string of length zero or one is a palindrome.  Anything longer must
have the first and last letter the same, and the in-between letters
must be a palindrome.

So again avoiding the issue of punctuation and spaces,

function Is_Palindrome (S : String) return Boolean is
begin
    return S'Length <= 1 or else
               Is_Palindrome (S(Natural'Succ(S'First) ..
Natural'Pred(S'Last))));
end Is_Palindrome;

regards
Bill Taylor ([log in to unmask])

ATOM RSS1 RSS2