Long year: Difference between revisions

Content deleted Content added
Peak (talk | contribs)
Peak (talk | contribs)
Line 841: Line 841:
'''Works with gojq, the Go implementation of jq'''
'''Works with gojq, the Go implementation of jq'''


Using Zeller's congruence ...<lang jq>
===Using Zeller's congruence===
<lang jq>
# Use Zeller's Congruence to determine the day of the week, given
# Use Zeller's Congruence to determine the day of the week, given
# year, month and day as integers in the conventional way.
# year, month and day as integers in the conventional way.
Line 869: Line 870:
{{out}}
{{out}}
<pre>
<pre>
Long years in 1900-2100 inclusive:
Long years from 1900 to 2100 inclusive:
1903, 1908, 1914, 1920, 1925, 1931, 1936, 1942, 1948, 1953
1903, 1908, 1914, 1920, 1925, 1931, 1936, 1942, 1948, 1953
1959, 1964, 1970, 1976, 1981, 1987, 1992, 1998, 2004, 2009
1959, 1964, 1970, 1976, 1981, 1987, 1992, 1998, 2004, 2009
Line 875: Line 876:
2071, 2076, 2082, 2088, 2093, 2099
2071, 2076, 2082, 2088, 2093, 2099
</pre>
</pre>

=== Using mktime ===
<lang jq># Use jq's mktime and gmtime to produce the day of week
# with 0 for Sunday, 1 for Monday, etc
# $year $month $day are conventional
def day_of_week($year; $month; $day):
[$year, $month - 1, $day, 0, 0, 1, 0, 0] | mktime | gmtime | .[-2];

# 4 corresponds to Thursday
def has53weeks:
day_of_week(.; 1; 1) == 4 or day_of_week(.; 12; 31) == 4;

def nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;

"Long years from 1900 to 2100 inclusive:",
([range(1900;2101) | select(has53weeks)] | nwise(10) | join(", "))
</lang>
{{out}}
As above.


=={{header|Julia}}==
=={{header|Julia}}==