September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,15 @@
Use Zeller's Congruence to determine the day of the week, given
# year, month and day as integers in the conventional way.
# Emit 0 for Saturday, 1 for Sunday, etc.
#
def day_of_week(year; month; day):
if month == 1 or month == 2 then
[month + 12, year - 1]
else
[month, year]
end
| day + (13*(.[0] + 1)/5|floor)
+ (.[1]%100) + ((.[1]%100)/4|floor)
+ (.[1]/400|floor) - 2*(.[1]/100|floor)
| . % 7
;

View file

@ -0,0 +1,25 @@
def weekday_of_last_day_of_month(year; month):
def day_before(day): (6+day) % 7;
if month==12 then day_before( day_of_week(year+1; 1; 1) )
else day_before( day_of_week( year; month+1; 1 ) )
end
;
# The only case where the month has 5 weekends is when the last day
# of the month falls on a Sunday and the month has 31 days.
#
def five_weekends(from; to):
reduce range(from; to) as $year
([]; reduce (1,3,5,7,8,10,12) as $month # months with 31 days
(.;
weekday_of_last_day_of_month($year; $month) as $day
| if $day == 1 then . + [[ $year, $month]] else . end ))
;
# Input [year, month] as conventional integers; print e.g. "Jan 2001"
def pp:
def month:
["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][.-1];
"\(.[1] | month) \(.[0])"
;

View file

@ -0,0 +1,7 @@
five_weekends(1900;2101)
| "There are \(length) months with 5 weekends from 1900 to 2100 inclusive;",
"the first and last five are as follows:",
( .[0: 5][] | pp),
"...",
( .[length-5: ][] | pp),
"In this period, there are \( [range(1900;2101)] - map( .[0] ) | length ) years which have no five-weekend months."

View file

@ -0,0 +1,15 @@
$ jq -r -n -f Five_Weekends.jq
There are 201 months with 5 weekends from 1900 to 2100 inclusive;
the first and last five are as follows:
Mar 1901
Aug 1902
May 1903
Jan 1904
Jul 1904
...
Mar 2097
Aug 2098
May 2099
Jan 2100
Oct 2100
In this period, there are 29 years which have no five-weekend months.