RosettaCodeData/Task/Palindrome-detection/Phix/palindrome-detection.phix
2017-09-25 22:28:19 +02:00

24 lines
839 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")