-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpal.d
42 lines (37 loc) · 776 Bytes
/
pal.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
toLower: proc(s:string): string{
c = s[0]
if c >= 'A' and c <= 'Z' {
return chr(asc(c) + 32)
}
return c
}
isPalindrome: proc(s:string): bool {
i=0 while i < length(s) do i = i + 1 {
if toLower(s[i]) != toLower(s[length(s)-i-1]) {
return false
}
}
return true
}
toString: proc(b:bool): string {
if b {
return 'true'
} else {
return 'false'
}
}
tester: proc(s:string, expected:bool) {
is = isPalindrome(s)
if is == expected {
println s + " is correctly " + toString(is)
} else {
exit s + " is UNEXPECTEDLY " + toString(is)
}
}
tester("hello", false)
tester("Hello", false)
tester("racecar", true)
tester("RaceCar", true)
tester("madamimadam", true)
tester("MadamIMAdam", true)
tester("Madam, I'm Adam", false)