24 lines
839 B
Text
24 lines
839 B
Text
function is_palindrome(sequence s)
|
||
return s==reverse(s)
|
||
end function
|
||
|
||
?is_palindrome("rotator") -- prints 1
|
||
?is_palindrome("tractor") -- prints 0
|
||
|
||
constant punctuation = " `~!@#$%^&*()-=_+[]{}\\|;:',.<>/?",
|
||
nulls = repeat("",length(punctuation))
|
||
|
||
function extra_credit(sequence s)
|
||
s = utf8_to_utf32(lower(substitute_all(s,punctuation,nulls)))
|
||
return s==reverse(s)
|
||
end function
|
||
|
||
-- these all print 1 (true)
|
||
?extra_credit("Madam, I'm Adam.")
|
||
?extra_credit("A man, a plan, a canal: Panama!")
|
||
?extra_credit("In girum imus nocte et consumimur igni")
|
||
?extra_credit("人人為我,我為人人")
|
||
?extra_credit("Я иду с мечем, судия")
|
||
?extra_credit("아들딸들아")
|
||
?extra_credit("가련하시다 사장집 아들딸들아 집장사 다시 하련가")
|
||
?extra_credit("tregða, gón, reiði - er nóg að gert")
|