Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Five-weekends/Jq/five-weekends-1.jq
Normal file
15
Task/Five-weekends/Jq/five-weekends-1.jq
Normal 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
|
||||
;
|
||||
25
Task/Five-weekends/Jq/five-weekends-2.jq
Normal file
25
Task/Five-weekends/Jq/five-weekends-2.jq
Normal 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])"
|
||||
;
|
||||
7
Task/Five-weekends/Jq/five-weekends-3.jq
Normal file
7
Task/Five-weekends/Jq/five-weekends-3.jq
Normal 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."
|
||||
15
Task/Five-weekends/Jq/five-weekends-4.jq
Normal file
15
Task/Five-weekends/Jq/five-weekends-4.jq
Normal 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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue