Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
19
Task/Five-weekends/DuckDB/five-weekends.duckdb
Normal file
19
Task/Five-weekends/DuckDB/five-weekends.duckdb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
create or replace function day_before(day) as (6+day) % 7;
|
||||
|
||||
create or replace function weekday_of_last_day_of_month(year, month) as (
|
||||
if(month=12,
|
||||
day_before( extract('dayofweek' from make_date(year+1, 1, 1) )),
|
||||
day_before( extract('dayofweek' from make_date( year, month+1, 1 ) ) ))
|
||||
);
|
||||
|
||||
# The only case where the month has 5 full weekends is when the last day
|
||||
# of the month falls on a Sunday (0) and the month has 31 days.
|
||||
#
|
||||
create or replace function five_weekends(start, stop) as table (
|
||||
select year, month
|
||||
from range(start, stop) as t(year),
|
||||
unnest([1,3,5,7,8,10,12]) as u(month) -- months with 31 days
|
||||
where weekday_of_last_day_of_month(year, month) = 0
|
||||
);
|
||||
|
||||
from five_weekends(1900, 2101) order by year, month;
|
||||
54
Task/Five-weekends/FutureBasic/five-weekends.basic
Normal file
54
Task/Five-weekends/FutureBasic/five-weekends.basic
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// Calculate months having 5 Fridays,
|
||||
// 5 Saturdays, and 5 Sundays
|
||||
// from year 1900 through 2100
|
||||
//
|
||||
//=================================================================
|
||||
// DayOfTheWeek - returns day of the week (Gregorian only)
|
||||
//
|
||||
// on entry: month, day, year
|
||||
// on exit: result = index to days
|
||||
// (0 = Sat, 1 = Sun,... 5 = Thu, 6 = Fri)
|
||||
//
|
||||
local fn DayOfTheWeek (month as Int, day as Int, year as Int) as int
|
||||
Int result
|
||||
if month < 3 then month+=12: year--
|
||||
result = (day + fix(((month + 1) * 13) / 5) + year ¬
|
||||
+ fix(year / 4) - fix(year / 100) + fix(year / 400)) % 7
|
||||
end fn = result
|
||||
|
||||
CFStringRef MonthNames(12) = {@"Greg Months",@"January",@"February",¬
|
||||
@"March",@"April",@"May",@"June",@"July",¬
|
||||
@"August",@"September",@"October",¬
|
||||
@"November", @"December"}
|
||||
|
||||
window 1,@"Five weekends"
|
||||
print
|
||||
|
||||
Int x, mm, yyyy
|
||||
Int tot, none
|
||||
CFStringRef res
|
||||
|
||||
for yyyy = 1900 to 2100
|
||||
res = @""
|
||||
for mm = 1 to 12 step 2
|
||||
if mm == 9 then mm = 8
|
||||
if fn DayOfTheWeek(mm,1,yyyy) == 6
|
||||
res = concat (res,MonthNames(mm), @" ")
|
||||
tot++
|
||||
end if
|
||||
next mm
|
||||
if len(res) < 1 then none++
|
||||
if ((yyyy < 1906) && (len(res) > 1)) || ((yyyy > 2094) && (len(res) > 1))
|
||||
print "Year ";yyyy;": ";: print res
|
||||
else
|
||||
if yyyy % 30 == 0 then print " ..."
|
||||
end if
|
||||
next yyyy
|
||||
|
||||
print
|
||||
print "=========================="
|
||||
print "Total months with = " ;tot
|
||||
print "Total years without = ";none
|
||||
|
||||
handleEvents
|
||||
36
Task/Five-weekends/Red/five-weekends.red
Normal file
36
Task/Five-weekends/Red/five-weekends.red
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
Red [ "Five Weekends - Hinjo, 20 July 2025" ]
|
||||
|
||||
; get day from year, month, week, and weekday!
|
||||
getday: function [y[integer!] m[integer!] w[integer!] wd[integer!]] [
|
||||
fd: to-date reduce [1 m y] ; first day!
|
||||
swd: fd/weekday + 1 if swd > 7 [swd: 1] ; shift from mon=1 to sun=1
|
||||
ofs: (w - 1) * 7 + (wd - swd) ; offset
|
||||
d: fd + ofs ; date
|
||||
either d/month = m [d/day] [0] ; return day or zero!
|
||||
]
|
||||
|
||||
mo: system/locale/months
|
||||
tfw: 0 ; total five weekends
|
||||
boring: 0 ; total boring years
|
||||
awesome: 0 ; total owesome years
|
||||
|
||||
y: 1900 while [y <= 2100] [ fwy: 0 ; five weekends in year
|
||||
prin [y]
|
||||
foreach m [1 3 5 7 8 10 12] [
|
||||
if 1 = d: getday y m 1 6 [ fwy: fwy + 1
|
||||
prin [" " mo/:m]
|
||||
]
|
||||
]
|
||||
tfw: tfw + fwy
|
||||
either fwy > 0 [
|
||||
print [" ==> Five weekends: " fwy]
|
||||
if fwy > 1 [ awesome: awesome + 1]
|
||||
][
|
||||
boring: boring + 1
|
||||
print [" ==> Boring year!"]
|
||||
]
|
||||
y: y + 1
|
||||
]
|
||||
print ["Total five weekends: " tfw]
|
||||
print ["Total boring years: " boring]
|
||||
print ["Total years with multiple five weekends months: " awesome]
|
||||
Loading…
Add table
Add a link
Reference in a new issue