Palindrome detection: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 2,375:
true
</code>
 
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn IsCleanStringPalindrome( testStr as CFStringRef ) as BOOL
NSUInteger i
BOOL result = NO
NSUInteger strLen = len(testStr)
for i = 0 to strLen / 2
if ( fn StringCharacterAtIndex( testStr, i ) != fn StringCharacterAtIndex( testStr, strLen -i -1 ) )
result = NO
exit fn
end if
next
result = YES
end fn = result
 
local fn IsDirtyStringPalindrome( dirtyStr as CFStringRef )
BOOL result = NO
CFStringRef tempStr
CFStringRef lowerCaseStr = fn StringLowercaseString( dirtyStr )
CFStringRef removeStr = @"!\"#$%&'()*+,-./:;<=>?@[]^_ {|}~"
NSUInteger i, count = len(removeStr)
tempStr = lowerCaseStr
for i = 0 to count -1
CFStringRef chrStr = fn StringWithFormat( @"%c", fn StringCharacterAtIndex( removeStr, i ) )
tempStr = fn StringByReplacingOccurrencesOfString( tempStr, chrStr, @"" )
next
result = fn IsCleanStringPalindrome( tempStr )
end fn = result
 
 
local fn PalindromeTest( testStr as CFStringRef )
BOOL result = NO
result = fn IsCleanStringPalindrome( testStr )
if ( result == YES )
NSLog( @"%17s : %@", fn StringUTF8String( @"Clean palindrome" ), testStr ) : exit fn
else
result = fn IsDirtyStringPalindrome( testStr )
if ( result == YES )
NSLog( @"%17s : %@", fn StringUTF8String( @"Dirty palindrome" ), testStr ) : exit fn
else
NSLog( @"%17s : %@", fn StringUTF8String( @"Not a palindrome" ), testStr )
end if
end if
end fn
 
fn PalindromeTest( @"racecar" )
fn PalindromeTest( @"level" )
fn PalindromeTest( @"rosetta" )
fn PalindromeTest( @"rotavator" )
fn PalindromeTest( @"13231+464+989=989+464+13231" )
fn PalindromeTest( @"Was it a car or a cat I saw?" )
fn PalindromeTest( @"Did Hannah see bees? Hannah did." )
fn PalindromeTest( @"This sentence is not a palindrome." )
fn PalindromeTest( @"123 456 789 897 654 321" )
fn PalindromeTest( @"123 456 789 987 654 321" )
fn PalindromeTest( @"Radar" )
fn PalindromeTest( @"abba" )
fn PalindromeTest( @"boom " )
fn PalindromeTest( @"radar" )
fn PalindromeTest( @"civic" )
fn PalindromeTest( @"great" )
fn PalindromeTest( @"Madam, I'm Adam." )
fn PalindromeTest( @"salàla" )
fn PalindromeTest( @"A man, a plan, a canal: Panama" )
fn PalindromeTest( @"a man a plan a canal panama" )
fn PalindromeTest( @"Egad, a base tone denotes a bad age" )
fn PalindromeTest( @"In girum imus nocte et consumimur igni" )
fn PalindromeTest( @"sees" )
fn PalindromeTest( @"solo" )
fn PalindromeTest( @"solos" )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Clean palindrome : racecar
Clean palindrome : level
Not a palindrome : rosetta
Clean palindrome : rotavator
Clean palindrome : 13231+464+989=989+464+13231
Dirty palindrome : Was it a car or a cat I saw?
Dirty palindrome : Did Hannah see bees? Hannah did.
Not a palindrome : This sentence is not a palindrome.
Not a palindrome : 123 456 789 897 654 321
Clean palindrome : 123 456 789 987 654 321
Dirty palindrome : Radar
Clean palindrome : abba
Not a palindrome : boom
Clean palindrome : radar
Clean palindrome : civic
Not a palindrome : great
Dirty palindrome : Madam, I'm Adam.
Not a palindrome : salàla
Dirty palindrome : A man, a plan, a canal: Panama
Dirty palindrome : a man a plan a canal panama
Dirty palindrome : Egad, a base tone denotes a bad age
Dirty palindrome : In girum imus nocte et consumimur igni
Clean palindrome : sees
Not a palindrome : solo
Clean palindrome : solos
</pre>
 
 
 
=={{header|Fōrmulæ}}==
719

edits