Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,32 @@
|
|||
on palindromeDates(startYear, targetNumber)
|
||||
script o
|
||||
property output : {}
|
||||
end script
|
||||
|
||||
set counter to 0
|
||||
set y to startYear
|
||||
repeat until ((counter = targetNumber) or (y > 9999))
|
||||
-- Derive a month number from the last two digits of the current year number. It's valid if it's in the range 1 to 12.
|
||||
set m to y mod 10 * 10 + y mod 100 div 10
|
||||
if ((m > 0) and (m < 13)) then
|
||||
-- Derive a day number from the first two digits of the year number.
|
||||
set d to y div 100 mod 10 * 10 + y div 1000
|
||||
-- It's valid if it's between 1 and 28. Otherwise, if it's between 29 and 31, check that it fits the month and year.
|
||||
-- In fact though, it'll only ever be 2 or 12 in the period containing the 15 palindromic dates after 2020.
|
||||
if ((d > 0) and ¬
|
||||
((d < 29) ¬
|
||||
or ((d < 31) and ((m is not 2) or ((d is 29) and (y mod 4 is 0) and ((y mod 100 > 0) or (y mod 400 is 0))))) ¬
|
||||
or ((d is 31) and (m is not in {2, 4, 9, 6, 11})))) then
|
||||
-- If the figures represent a valid date, add a yyyy-mm-dd format text to the end of the output list.
|
||||
tell ((100000000 + y * 10000 + m * 100 + d) as text) to ¬
|
||||
set end of o's output to text 2 thru 5 & ("-" & text 6 thru 7) & ("-" & text 8 thru 9)
|
||||
set counter to counter + 1
|
||||
end if
|
||||
end if
|
||||
set y to y + 1
|
||||
end repeat
|
||||
|
||||
return o's output
|
||||
end palindromeDates
|
||||
|
||||
palindromeDates(2021, 15)
|
||||
117
Task/Palindrome-dates/AppleScript/palindrome-dates-2.applescript
Normal file
117
Task/Palindrome-dates/AppleScript/palindrome-dates-2.applescript
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
use AppleScript version "2.4"
|
||||
use framework "Foundation"
|
||||
use scripting additions
|
||||
|
||||
|
||||
-- palinYearsInRange :: Int -> Int -> [String]
|
||||
on palinYearsInRange(fromYear, toYear)
|
||||
|
||||
concatMap(palinDay(iso8601Formatter()), ¬
|
||||
enumFromTo(fromYear, toYear))
|
||||
|
||||
end palinYearsInRange
|
||||
|
||||
|
||||
-- palinDay :: DateFormatter -> Int -> [String]
|
||||
on palinDay(formatter)
|
||||
script
|
||||
property fmtr : formatter
|
||||
on |λ|(y)
|
||||
-- Either an empty list or a list containing a valid
|
||||
-- palindromic date for a year in the range [1000 .. 9999]
|
||||
if 10000 > y and 999 < y then
|
||||
set s to y as string
|
||||
set {m, m1, d, d1} to reverse of characters of s
|
||||
set mbDate to s & "-" & m & m1 & "-" & d & d1
|
||||
|
||||
if missing value is not ¬
|
||||
(fmtr's dateFromString:(mbDate & ¬
|
||||
"T00:00:00+00:00")) then
|
||||
{mbDate}
|
||||
else
|
||||
{}
|
||||
end if
|
||||
else
|
||||
{}
|
||||
end if
|
||||
end |λ|
|
||||
end script
|
||||
end palinDay
|
||||
|
||||
|
||||
--------------------------- TEST ---------------------------
|
||||
on run
|
||||
set xs to palinYearsInRange(2021, 9999)
|
||||
|
||||
unlines({¬
|
||||
"Count of palindromic dates [2021..9999]: " & ¬
|
||||
((length of xs) as string), ¬
|
||||
"", ¬
|
||||
"First 15:", unlines(items 1 thru 15 of xs), "", ¬
|
||||
"Last 15:", unlines(items -15 thru -1 of xs)})
|
||||
end run
|
||||
|
||||
|
||||
-------------------- GENERIC FUNCTIONS ---------------------
|
||||
|
||||
-- concatMap :: (a -> [b]) -> [a] -> [b]
|
||||
on concatMap(f, xs)
|
||||
set lng to length of xs
|
||||
set acc to {}
|
||||
tell mReturn(f)
|
||||
repeat with i from 1 to lng
|
||||
set acc to acc & (|λ|(item i of xs, i, xs))
|
||||
end repeat
|
||||
end tell
|
||||
return acc
|
||||
end concatMap
|
||||
|
||||
|
||||
-- enumFromTo :: Int -> Int -> [Int]
|
||||
on enumFromTo(m, n)
|
||||
if m ≤ n then
|
||||
set lst to {}
|
||||
repeat with i from m to n
|
||||
set end of lst to i
|
||||
end repeat
|
||||
lst
|
||||
else
|
||||
{}
|
||||
end if
|
||||
end enumFromTo
|
||||
|
||||
|
||||
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
|
||||
on mReturn(f)
|
||||
-- 2nd class handler function lifted into 1st class script wrapper.
|
||||
if script is class of f then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
|
||||
-- iso8601Formatter :: () -> NSISO8601DateFormatter
|
||||
on iso8601Formatter()
|
||||
tell current application
|
||||
set formatter to its NSISO8601DateFormatter's alloc's init()
|
||||
set formatOptions of formatter to ¬
|
||||
(its NSISO8601DateFormatWithInternetDateTime as integer)
|
||||
return formatter
|
||||
end tell
|
||||
end iso8601Formatter
|
||||
|
||||
|
||||
-- unlines :: [String] -> String
|
||||
on unlines(xs)
|
||||
-- A single string formed by the intercalation
|
||||
-- of a list of strings with the newline character.
|
||||
set {dlm, my text item delimiters} to ¬
|
||||
{my text item delimiters, linefeed}
|
||||
set str to xs as text
|
||||
set my text item delimiters to dlm
|
||||
str
|
||||
end unlines
|
||||
Loading…
Add table
Add a link
Reference in a new issue