Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
|
|
@ -0,0 +1,59 @@
|
|||
(defun palindrome-type (text)
|
||||
(cond ((exact-palindrom-p text) 'exact)
|
||||
((inexact-palindrome-p text) 'inexact)
|
||||
(t 'not-a-palindrome)))
|
||||
|
||||
(defun exact-palindrom-p (text)
|
||||
(eq text (implode (reverse (explode text)))))
|
||||
|
||||
(defun inexact-palindrome-p (text)
|
||||
(exact-palindrom-p (implode (normalise (explode text)))))
|
||||
|
||||
(defun reverse (list (result . ()))
|
||||
(map '(lambda (e) (setq result (cons e result)))
|
||||
list)
|
||||
result)
|
||||
|
||||
(defun normalise (chars)
|
||||
(cond ((null chars)
|
||||
nil)
|
||||
((not (alphanumeric-p (car chars)))
|
||||
(normalise (cdr chars)))
|
||||
((upper-case-p (car chars))
|
||||
(cons (to-lower-case (car chars))
|
||||
(normalise (cdr chars))))
|
||||
(t
|
||||
(cons (car chars) (normalise (cdr chars))))))
|
||||
|
||||
(defun between-p (lowest-value n highest-value)
|
||||
(not (or (lessp n lowest-value)
|
||||
(greaterp n highest-value))))
|
||||
|
||||
(defun alphanumeric-p (ch)
|
||||
(or (lower-case-p ch) (upper-case-p ch) (digit-p ch)))
|
||||
|
||||
(defun digit-p (ch)
|
||||
(between-p (add1 (ordinal '/))
|
||||
(ordinal ch)
|
||||
(sub1 (ordinal ':))))
|
||||
|
||||
(defun upper-case-p (ch)
|
||||
(between-p (ordinal 'A) (ordinal ch) (ordinal 'Z)))
|
||||
|
||||
(defun lower-case-p (ch)
|
||||
(between-p (ordinal 'a) (ordinal ch) (ordinal 'z)))
|
||||
|
||||
(defun to-lower-case (ch)
|
||||
(character (plus (ordinal ch)
|
||||
(difference (ordinal 'a) (ordinal 'A)))))
|
||||
|
||||
(defun examples ()
|
||||
(map '(lambda (text)
|
||||
(printc '!" text '!"
|
||||
'! is! (palindrome-type text)))
|
||||
'(a
|
||||
abba Abba
|
||||
abcba
|
||||
baba
|
||||
Able! was! I! ere! I! saw! Elba!!
|
||||
In! girum! imus! nocte,! et! consumimur! igni)))
|
||||
20
Task/Palindrome-detection/EasyLang/palindrome-detection.easy
Normal file
20
Task/Palindrome-detection/EasyLang/palindrome-detection.easy
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
func$ reverse s$ .
|
||||
a$[] = strchars s$
|
||||
for i = 1 to len a$[] div 2
|
||||
swap a$[i] a$[len a$[] - i + 1]
|
||||
.
|
||||
return strjoin a$[]
|
||||
.
|
||||
func palin s$ .
|
||||
if s$ = reverse s$
|
||||
return 1
|
||||
.
|
||||
return 0
|
||||
.
|
||||
for s$ in [ "rotor" "rosetta" "step on no pets" "été" "🦊😀🦊" ]
|
||||
if palin s$ = 1
|
||||
print s$ & " is a palindrome"
|
||||
else
|
||||
print s$ & " is not a palindrome"
|
||||
.
|
||||
.
|
||||
Loading…
Add table
Add a link
Reference in a new issue