Long year: Difference between revisions

Content added Content deleted
(Added J implementation)
Line 836: Line 836:
2037
2037
2043</pre>
2043</pre>

=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''

Using Zeller's congruence ...<lang jq>
# 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 ;

def has53weeks:
day_of_week(.; 1; 1) == 5 or day_of_week(.; 12; 31) == 5;

# To display results neatly:
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}}
<pre>
Long years in 1900-2100 inclusive:
1903, 1908, 1914, 1920, 1925, 1931, 1936, 1942, 1948, 1953
1959, 1964, 1970, 1976, 1981, 1987, 1992, 1998, 2004, 2009
2015, 2020, 2026, 2032, 2037, 2043, 2048, 2054, 2060, 2065
2071, 2076, 2082, 2088, 2093, 2099
</pre>


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