Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,3 @@
(defun test-if-palindrome (text)
(setq text (replace-regexp-in-string "[[:space:][:punct:]]" "" text)) ; remove spaces and punctuation, by replacing them with nothing
(string-equal-ignore-case text (reverse text))) ; ignore case when looking at reversed text

View file

@ -1,6 +1,6 @@
val .ispal = fn(.s) len(.s) > 0 and .s == reverse .s
val ispal = fn s:len(s) > 0 and s == reverse(s)
val .tests = h{
val tests = {
"": false,
"z": true,
"aha": true,
@ -17,7 +17,7 @@ val .tests = h{
"ingirumimusnocteetconsumimurigni": true,
}
for .word in sort(keys .tests) {
val .foundpal = .ispal(.word)
writeln .word, ": ", .foundpal, if(.foundpal == .tests[.word]: ""; " (FAILED TEST)")
for word in sort(keys(tests)) {
val foundpal = ispal(word)
writeln word, ": ", foundpal, if(foundpal == tests[word]: ""; " (FAILED TEST)")
}

View file

@ -0,0 +1,6 @@
function IsPalindrome(s: string) := s = s[::-1];
begin
Println(IsPalindrome('arozaupalanalapuazora'));
Println(IsPalindrome('abcd'));
end.

View file

@ -0,0 +1,37 @@
$ENTRY Go {
= <Test 'rotor'>
<Test 'racecar'>
<Test 'RACEcar'>
<Test 'level'>
<Test 'rosetta'>
<Test 'A man, a plan, a canal: Panama'>
<Test 'Egad, a base tone denotes a bad age'>
<Test 'This is not a palindrome'>;
};
Test {
e.W, <Palindrome e.W> <InexactPalindrome e.W>: {
True s.1 = <Prout e.W ': exact palindrome'>;
s.1 True = <Prout e.W ': inexact palindrome'>;
False False = <Prout e.W ': not a palindrome'>;
};
};
InexactPalindrome {
e.W = <Palindrome <Filter ('ABCDEFGHIJKLMNOPQRSTUVWXYZ') <Upper e.W>>>;
};
Filter {
(e.Keep) = ;
(e.Keep) s.C e.W, e.Keep: {
e.1 s.C e.2 = s.C <Filter (e.Keep) e.W>;
e.1 = <Filter (e.Keep) e.W>;
};
};
Palindrome {
= True;
s.C = True;
s.C e.W s.C = <Palindrome e.W>;
e.X = False;
};

View file

@ -5,9 +5,10 @@ for i = 1 to 4
print w$;" is ";isPalindrome$(w$);" Palindrome"
next
FUNCTION isPalindrome$(str$)
for i = 1 to len(str$)
a$ = upper$(mid$(str$,i,1))
if (a$ >= "A" and a$ <= "Z") or (a$ >= "0" and a$ <= "9") then b$ = b$ + a$: c$ = a$ + c$
next i
if b$ <> c$ then isPalindrome$ = "not"
function isPalindrome$(str$)
for i = 1 to len(str$)
a$ = upper$(mid$(str$,i,1))
if (a$ >= "A" and a$ <= "Z") or (a$ >= "0" and a$ <= "9") then b$ = b$ + a$: c$ = a$ + c$
next i
if b$ <> c$ then isPalindrome$ = "not"
end function

View file

@ -0,0 +1,2 @@
IsPal ← ≍⇌.+×32<@a.▽:⟜∊:/⊂+⊙¤"Aa"⇡26
IsPal "A man, a plan, a canal: Panama!"