Palindrome dates: Difference between revisions
Content added Content deleted
m (added a clause.) |
(→{{header|AppleScript}}: Added subheadings) |
||
Line 44: | Line 44: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
===Procedural=== |
|||
<lang applescript>on palindromeDates(startYear, targetNumber) |
<lang applescript>on palindromeDates(startYear, targetNumber) |
||
script o |
script o |
||
Line 81: | Line 81: | ||
<pre>{"2021-12-02", "2030-03-02", "2040-04-02", "2050-05-02", "2060-06-02", "2070-07-02", "2080-08-02", "2090-09-02", "2101-10-12", "2110-01-12", "2111-11-12", "2120-02-12", "2121-12-12", "2130-03-12", "2140-04-12"}</pre> |
<pre>{"2021-12-02", "2030-03-02", "2040-04-02", "2050-05-02", "2060-06-02", "2070-07-02", "2080-08-02", "2090-09-02", "2101-10-12", "2110-01-12", "2111-11-12", "2120-02-12", "2121-12-12", "2130-03-12", "2140-04-12"}</pre> |
||
===Functional=== |
|||
Or, for a functional composition (rather than a procedure), we can return a count and two samples of all palindromic dates for years in the range [2021 .. 9999], by assembling a function from reusable generics: |
|||
<lang applescript>use AppleScript version "2.4" |
<lang applescript>use AppleScript version "2.4" |
||
Line 91: | Line 90: | ||
-- palinYearsInRange :: Int -> Int -> [String] |
-- palinYearsInRange :: Int -> Int -> [String] |
||
on palinYearsInRange(fromYear, toYear) |
on palinYearsInRange(fromYear, toYear) |
||
concatMap(palinDay(iso8601Formatter()), ¬ |
concatMap(palinDay(iso8601Formatter()), ¬ |
||
enumFromTo(fromYear, toYear)) |
enumFromTo(fromYear, toYear)) |
||
end palinYearsInRange |
end palinYearsInRange |
||
Line 109: | Line 108: | ||
set {m, m1, d, d1} to reverse of characters of s |
set {m, m1, d, d1} to reverse of characters of s |
||
set mbDate to s & "-" & m & m1 & "-" & d & d1 |
set mbDate to s & "-" & m & m1 & "-" & d & d1 |
||
if missing value is not ¬ |
if missing value is not ¬ |
||
(fmtr's dateFromString:(mbDate & ¬ |
(fmtr's dateFromString:(mbDate & ¬ |
||
Line 124: | Line 124: | ||
---------------------------TEST |
--------------------------- TEST --------------------------- |
||
on run |
on run |
||
set xs to palinYearsInRange(2021, 9999) |
set xs to palinYearsInRange(2021, 9999) |
||
Line 137: | Line 137: | ||
-------------------- |
-------------------- GENERIC FUNCTIONS --------------------- |
||
-- concatMap :: (a -> [b]) -> [a] -> [b] |
-- concatMap :: (a -> [b]) -> [a] -> [b] |
||
Line 178: | Line 177: | ||
end if |
end if |
||
end mReturn |
end mReturn |
||
-- iso8601Formatter :: () -> NSISO8601DateFormatter |
-- iso8601Formatter :: () -> NSISO8601DateFormatter |
||
Line 188: | Line 188: | ||
end tell |
end tell |
||
end iso8601Formatter |
end iso8601Formatter |
||
-- unlines :: [String] -> String |
-- unlines :: [String] -> String |