Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Palindrome-detection/BCPL/palindrome-detection.bcpl
Normal file
43
Task/Palindrome-detection/BCPL/palindrome-detection.bcpl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
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))
|
||||
$)
|
||||
Loading…
Add table
Add a link
Reference in a new issue