Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,48 @@
set fiveWeekendMonths to {}
set noFiveWeekendYears to {}
set someDate to current date
set day of someDate to 1
repeat with someYear from 1900 to 2100
set year of someDate to someYear
set foundOne to false
repeat with someMonth in {January, March, May, July, ¬
August, October, December}
set month of someDate to someMonth
if weekday of someDate is Friday then
set foundOne to true
set end of fiveWeekendMonths to ¬
(someYear as text) & "-" & (someMonth as text)
end
end repeat
if not foundOne then
set end of noFiveWeekendYears to someYear
end
end repeat
set text item delimiters to ", "
set monthList to ¬
(items 1 thru 5 of fiveWeekendMonths as text) & ", ..." & linefeed & ¬
" ..., " & (items -5 thru end of fiveWeekendMonths as text)
set monthCount to count fiveWeekendMonths
set yearCount to count noFiveWeekendYears
set resultText to ¬
"Months with five weekends (" & monthCount & "): " & linefeed & ¬
" " & monthList & linefeed & linefeed & ¬
"Years with no such months (" & yearCount & "): "
set y to 1
repeat while y < yearCount
set final to y+11
if final > yearCount then
set final to yearCount
end
set resultText to ¬
resultText & linefeed & ¬
" " & (items y through final of noFiveWeekendYears as text)
set y to y + 12
end
resultText

View file

@ -0,0 +1,173 @@
-- TEST -----------------------------------------------------------------------
on run
fiveWeekends(1900, 2100)
end run
-- FIVE WEEKENDS --------------------------------------------------------------
-- fiveWeekends :: Int -> Int -> Record
on fiveWeekends(fromYear, toYear)
set lstYears to enumFromTo(fromYear, toYear)
-- yearMonthString :: (Int, Int) -> String
script yearMonthString
on |λ|(lstYearMonth)
((item 1 of lstYearMonth) as string) & " " & ¬
item (item 2 of lstYearMonth) of ¬
{"January", "", "March", "", "May", "", ¬
"July", "August", "", "October", "", "December"}
end |λ|
end script
-- addLongMonthsOfYear :: [(Int, Int)] -> [(Int, Int)]
script addLongMonthsOfYear
on |λ|(lstYearMonth, intYear)
-- yearMonth :: Int -> (Int, Int)
script yearMonth
on |λ|(intMonth)
{intYear, intMonth}
end |λ|
end script
lstYearMonth & ¬
map(yearMonth, my longMonthsStartingFriday(intYear))
end |λ|
end script
-- leanYear :: Int -> Bool
script leanYear
on |λ|(intYear)
0 = length of longMonthsStartingFriday(intYear)
end |λ|
end script
set lstFullMonths to map(yearMonthString, ¬
foldl(addLongMonthsOfYear, {}, lstYears))
set lstLeanYears to filter(leanYear, lstYears)
{{|number|:length of lstFullMonths}, ¬
{firstFive:(items 1 thru 5 of lstFullMonths)}, ¬
{lastFive:(items -5 thru -1 of lstFullMonths)}, ¬
{leanYearCount:length of lstLeanYears}, ¬
{leanYears:lstLeanYears}}
end fiveWeekends
-- longMonthsStartingFriday :: Int -> [Int]
on longMonthsStartingFriday(intYear)
-- startIsFriday :: Int -> Bool
script startIsFriday
on |λ|(iMonth)
weekday of calendarDate(intYear, iMonth, 1) is Friday
end |λ|
end script
filter(startIsFriday, [1, 3, 5, 7, 8, 10, 12])
end longMonthsStartingFriday
-- calendarDate :: Int -> Int -> Int -> Date
on calendarDate(intYear, intMonth, intDay)
tell (current date)
set {its year, its month, its day, its time} to ¬
{intYear, intMonth, intDay, 0}
return it
end tell
end calendarDate
-- GENERIC FUNCTIONS ----------------------------------------------------------
-- enumFromTo :: Enum a => a -> a -> [a]
on enumFromTo(m, n)
set {intM, intN} to {fromEnum(m), fromEnum(n)}
if intM > intN then
set d to -1
else
set d to 1
end if
set lst to {}
if class of m is text then
repeat with i from intM to intN by d
set end of lst to chr(i)
end repeat
else
repeat with i from intM to intN by d
set end of lst to i
end repeat
end if
return lst
end enumFromTo
-- fromEnum :: Enum a => a -> Int
on fromEnum(x)
set c to class of x
if c is boolean then
if x then
1
else
0
end if
else if c is text then
if x "" then
id of x
else
missing value
end if
else
x as integer
end if
end fromEnum
-- 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
-- foldl :: (a -> b -> a) -> a -> [b] -> a
on foldl(f, startValue, xs)
tell mReturn(f)
set v to startValue
set lng to length of xs
repeat with i from 1 to lng
set v to |λ|(v, item i of xs, i, xs)
end repeat
return v
end tell
end foldl
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to |λ|(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- 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

View file

@ -0,0 +1,7 @@
{{|number|:201},
{firstFive:{"1901 March", "1902 August", "1903 May", "1904 January", "1904 July"}},
{lastFive:{"2097 March", "2098 August", "2099 May", "2100 January", "2100 October"}},
{leanYearCount:29},
{leanYears:{1900, 1906, 1917, 1923, 1928, 1934, 1945, 1951, 1956, 1962, 1973, 1979,
1984, 1990, 2001, 2007, 2012, 2018, 2029, 2035, 2040, 2046, 2057, 2063, 2068, 2074,
2085, 2091, 2096}}}

View file

@ -0,0 +1,51 @@
on monthsWithFiveWeekends(startYear, endYear)
set Dec1 to (current date)
tell Dec1 to set {its day, its month, its year} to {1, December, startYear - 1}
set daysFromBaseFriday to (Dec1's weekday as integer) - Friday
set longMonths to {"January", "March", "May", "July", "August", "October", "December"}
set daysBetween to {31, 59, 61, 61, 31, 61, 61} -- Days since starts of preceding long months.
set hits to {}
set hitlessYears to {}
repeat with y from startYear to endYear
set noHIts to true
-- Find long months that begin on Fridays.
repeat with i from 1 to 7
set daysFromBaseFriday to daysFromBaseFriday + (daysBetween's item i)
if ((i = 2) and (y mod 4 = 0) and ((y mod 100 > 0) or (y mod 400 = 0))) then ¬
set daysFromBaseFriday to daysFromBaseFriday + 1 -- Leap year.
if (daysFromBaseFriday mod 7 = 0) then
set end of hits to (longMonths's item i) & (space & y)
set noHIts to false
end if
end repeat
if (noHIts) then set end of hitlessYears to y
end repeat
return {hits:hits, hitlessYears:hitlessYears}
end monthsWithFiveWeekends
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
on task()
set {startYear, endYear} to {1900, 2100}
set theResults to monthsWithFiveWeekends(startYear, endYear)
set output to {((count theResults's hits) as text) & " of the months from " & startYear & ¬
" to " & endYear & " have five weekends,", ¬
"the first and last five of these months being:"}
set end of output to join(theResults's hits's items 1 thru 5, ", ") & " …"
set end of output to "… " & join(theResults's hits's items -5 thru -1, ", ")
set hitlessCount to (count theResults's hitlessYears)
set end of output to linefeed & hitlessCount & " of the years have no such months:"
set cut to (hitlessCount + 1) div 2
set end of output to join(theResults's hitlessYears's items 1 thru cut, ", ")
set end of output to join(theResults's hitlessYears's items (cut + 1) thru -1, ", ")
return join(output, linefeed)
end task
task()

View file

@ -0,0 +1,8 @@
"201 of the months from 1900 to 2100 have five weekends,
the first and last five of these months being:
March 1901, August 1902, May 1903, January 1904, July 1904
March 2097, August 2098, May 2099, January 2100, October 2100
29 of the years have no such months:
1900, 1906, 1917, 1923, 1928, 1934, 1945, 1951, 1956, 1962, 1973, 1979, 1984, 1990, 2001
2007, 2012, 2018, 2029, 2035, 2040, 2046, 2057, 2063, 2068, 2074, 2085, 2091, 2096"