Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,75 @@
|
|||
use framework "Foundation"
|
||||
|
||||
------ CASE-INSENSITIVE PALINDROME, IGNORING SPACES ? ----
|
||||
|
||||
-- isPalindrome :: String -> Bool
|
||||
on isPalindrome(s)
|
||||
s = intercalate("", reverse of characters of s)
|
||||
end isPalindrome
|
||||
|
||||
-- toSpaceFreeLower :: String -> String
|
||||
on spaceFreeToLower(s)
|
||||
script notSpace
|
||||
on |λ|(s)
|
||||
s is not space
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
intercalate("", filter(notSpace, characters of toLower(s)))
|
||||
end spaceFreeToLower
|
||||
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
on run
|
||||
|
||||
isPalindrome(spaceFreeToLower("In girum imus nocte et consumimur igni"))
|
||||
|
||||
--> true
|
||||
|
||||
end run
|
||||
|
||||
|
||||
-------------------- GENERIC FUNCTIONS -------------------
|
||||
|
||||
-- filter :: (a -> Bool) -> [a] -> [a]
|
||||
on filter(f, xs)
|
||||
tell mReturn(f)
|
||||
set lst to {}
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if |λ|(v, i, xs) then set end of lst to v
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end filter
|
||||
|
||||
|
||||
-- intercalate :: Text -> [Text] -> Text
|
||||
on intercalate(strText, lstText)
|
||||
set {dlm, my text item delimiters} to {my text item delimiters, strText}
|
||||
set strJoined to lstText as text
|
||||
set my text item delimiters to dlm
|
||||
return strJoined
|
||||
end intercalate
|
||||
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
|
||||
-- toLower :: String -> String
|
||||
on toLower(str)
|
||||
set ca to current application
|
||||
((ca's NSString's stringWithString:(str))'s ¬
|
||||
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
||||
end toLower
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
on isPalindrome(txt)
|
||||
set txt to join(txt, "") -- In case the input's a list (array).
|
||||
return (txt = join(reverse of txt's characters, ""))
|
||||
end isPalindrome
|
||||
|
||||
on join(lst, delim)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to delim
|
||||
set txt to lst as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return txt
|
||||
end join
|
||||
|
||||
return isPalindrome("Radar")
|
||||
|
|
@ -0,0 +1 @@
|
|||
true
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
considering case
|
||||
return isPalindrome("Radar")
|
||||
end considering
|
||||
|
|
@ -0,0 +1 @@
|
|||
false
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
ignoring case, white space, hyphens and punctuation
|
||||
return isPalindrome("Was it a 😀car, or a c😀at-I-saw?")
|
||||
end ignoring
|
||||
|
|
@ -0,0 +1 @@
|
|||
true
|
||||
Loading…
Add table
Add a link
Reference in a new issue