43 lines
980 B
Text
43 lines
980 B
Text
get "libhdr"
|
|
|
|
let palindrome(s) = valof
|
|
$( let l = s%0
|
|
for i = 1 to l/2
|
|
unless s%i = s%(l+1-i)
|
|
resultis false
|
|
resultis true
|
|
$)
|
|
|
|
let inexact(s) = valof
|
|
$( let temp = vec 1+256/BYTESPERWORD
|
|
temp%0 := 0
|
|
for i = 1 to s%0 do
|
|
$( let ch = s%i | 32
|
|
if '0'<=ch & ch<='9' | 'a'<=ch & ch<='z' then
|
|
$( temp%0 := temp%0 + 1
|
|
temp%(temp%0) := ch
|
|
$)
|
|
$)
|
|
resultis palindrome(temp)
|
|
$)
|
|
|
|
let check(s) =
|
|
palindrome(s) -> "exact palindrome",
|
|
inexact(s) -> "inexact palindrome",
|
|
"not a palindrome"
|
|
|
|
let start() be
|
|
$( let tests = vec 8
|
|
tests!0 := "rotor"
|
|
tests!1 := "racecar"
|
|
tests!2 := "RACEcar"
|
|
tests!3 := "level"
|
|
tests!4 := "redder"
|
|
tests!5 := "rosetta"
|
|
tests!6 := "A man, a plan, a canal: Panama"
|
|
tests!7 := "Egad, a base tone denotes a bad age"
|
|
tests!8 := "This is not a palindrome"
|
|
|
|
for i = 0 to 8 do
|
|
writef("'%S': %S*N", tests!i, check(tests!i))
|
|
$)
|