77 lines
2.4 KiB
Plaintext
77 lines
2.4 KiB
Plaintext
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
|