Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Long-year/00-META.yaml
Normal file
2
Task/Long-year/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Long_year
|
||||
6
Task/Long-year/00-TASK.txt
Normal file
6
Task/Long-year/00-TASK.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Most years have 52 weeks, some have 53, according to [https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year ISO8601].
|
||||
|
||||
|
||||
;Task:
|
||||
Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
|
||||
<br><br>
|
||||
8
Task/Long-year/11l/long-year.11l
Normal file
8
Task/Long-year/11l/long-year.11l
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
F is_long_year(year)
|
||||
F p(year)
|
||||
R (year + (year I/ 4) - (year I/ 100) + (year I/ 400)) % 7
|
||||
R p(year) == 4 | p(year - 1) == 3
|
||||
|
||||
L(year) 2000..2100
|
||||
I is_long_year(year)
|
||||
print(year, end' ‘ ’)
|
||||
24
Task/Long-year/ALGOL-68/long-year.alg
Normal file
24
Task/Long-year/ALGOL-68/long-year.alg
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
BEGIN # find "long years" - years which have 53 weeks this is equivalent to #
|
||||
# finding years where 1st Jan or 31st Dec are Thursdays #
|
||||
# returns the day of the week of the specified date (d/m/y), Sunday = 1 #
|
||||
PROC day of week = ( INT d, m, y )INT:
|
||||
BEGIN
|
||||
INT mm := m;
|
||||
INT yy := y;
|
||||
IF mm <= 2 THEN
|
||||
mm := mm + 12;
|
||||
yy := yy - 1
|
||||
FI;
|
||||
INT j = yy OVER 100;
|
||||
INT k = yy MOD 100;
|
||||
(d + ( ( mm + 1 ) * 26 ) OVER 10 + k + k OVER 4 + j OVER 4 + 5 * j ) MOD 7
|
||||
END # day of week # ;
|
||||
# returns TRUE if year is a long year, FALSE otherwise #
|
||||
PROC is long year = ( INT year )BOOL:
|
||||
day of week( 1, 1, year ) = 5 OR day of week( 31, 12, year ) = 5;
|
||||
# show long years from 2000-2099 #
|
||||
print( ( "long years 2000-2099:" ) );
|
||||
FOR year FROM 2000 TO 2099 DO
|
||||
IF is long year( year ) THEN print( ( " ", whole( year, 0 ) ) ) FI
|
||||
OD
|
||||
END
|
||||
57
Task/Long-year/ALGOL-M/long-year.alg
Normal file
57
Task/Long-year/ALGOL-M/long-year.alg
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
BEGIN
|
||||
|
||||
COMMENT
|
||||
FIND ISO CALENDAR YEARS HAVING 53 WEEKS. THE SIMPLEST
|
||||
TEST IS THAT A GIVEN YEAR WILL BE "LONG" IF EITHER THE
|
||||
FIRST OR LAST DAY IS A THURSDAY;
|
||||
|
||||
% CALCULATE P MOD Q %
|
||||
INTEGER FUNCTION MOD(P, Q);
|
||||
INTEGER P, Q;
|
||||
BEGIN
|
||||
MOD := P - Q * (P / Q);
|
||||
END;
|
||||
|
||||
COMMENT
|
||||
RETURN DAY OF WEEK (SUN=0, MON=1, ETC.) FOR A GIVEN
|
||||
GREGORIAN CALENDAR DATE USING ZELLER'S CONGRUENCE;
|
||||
INTEGER FUNCTION DAYOFWEEK(MO, DA, YR);
|
||||
INTEGER MO, DA, YR;
|
||||
BEGIN
|
||||
INTEGER Y, C, Z;
|
||||
IF MO < 3 THEN
|
||||
BEGIN
|
||||
MO := MO + 10;
|
||||
YR := YR - 1;
|
||||
END
|
||||
ELSE MO := MO - 2;
|
||||
Y := MOD(YR, 100);
|
||||
C := YR / 100;
|
||||
Z := (26 * MO - 2) / 10;
|
||||
Z := Z + DA + Y + (Y / 4) + (C /4) - 2 * C + 777;
|
||||
DAYOFWEEK := MOD(Z, 7);
|
||||
END;
|
||||
|
||||
% RETURN 1 IF YEAR IS LONG, OTHERWISE 0 %
|
||||
INTEGER FUNCTION ISLONGYEAR(YR);
|
||||
INTEGER YR;
|
||||
BEGIN
|
||||
INTEGER THURSDAY;
|
||||
THURSDAY := 4;
|
||||
IF (DAYOFWEEK(1,1,YR) = THURSDAY) OR
|
||||
(DAYOFWEEK(12,31,YR) = THURSDAY) THEN
|
||||
ISLONGYEAR := 1
|
||||
ELSE
|
||||
ISLONGYEAR := 0;
|
||||
END;
|
||||
|
||||
% MAIN PROGRAM STARTS HERE %
|
||||
INTEGER YEAR;
|
||||
WRITE("ISO YEARS THAT WILL BE LONG IN THIS CENTURY:");
|
||||
WRITE("");
|
||||
FOR YEAR := 2000 STEP 1 UNTIL 2099 DO
|
||||
BEGIN
|
||||
IF ISLONGYEAR(YEAR) = 1 THEN WRITEON(YEAR);
|
||||
END;
|
||||
|
||||
END
|
||||
26
Task/Long-year/ALGOL-W/long-year.alg
Normal file
26
Task/Long-year/ALGOL-W/long-year.alg
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
begin % find "long years" - years which have 53 weeks %
|
||||
% this is equivalent to finding years where %
|
||||
% 1st Jan or 31st Dec are Thursdays %
|
||||
% finds the day of the week - Sunday = 1 %
|
||||
integer procedure Day_of_week ( integer value d, m, y );
|
||||
begin
|
||||
integer j, k, mm, yy;
|
||||
mm := m;
|
||||
yy := y;
|
||||
if mm <= 2 then begin
|
||||
mm := mm + 12;
|
||||
yy := yy - 1;
|
||||
end if_m_le_2;
|
||||
j := yy div 100;
|
||||
k := yy rem 100;
|
||||
(d + ( ( mm + 1 ) * 26 ) div 10 + k + k div 4 + j div 4 + 5 * j ) rem 7
|
||||
end Day_of_week;
|
||||
% returns true if year is a long year, false otherwise %
|
||||
logical procedure isLongYear ( integer value year );
|
||||
Day_of_week( 1, 1, year ) = 5 or Day_of_week( 31, 12, year ) = 5;
|
||||
% show long years from 2000-2099 %
|
||||
write( "long years 2000-2099:" );
|
||||
for year := 2000 until 2099 do begin
|
||||
if isLongYear( year ) then writeon( I_W := 5, S_W := 0, year )
|
||||
end for_year
|
||||
end.
|
||||
2
Task/Long-year/APL/long-year.apl
Normal file
2
Task/Long-year/APL/long-year.apl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
dec31weekday ← {7|⍵+⌊(⍵÷4)+⌊(⍵÷400)-⌊⍵÷100}
|
||||
isolongyear ← {(4 = dec31weekday ⍵) ∨ 3 = dec31weekday ⍵ - 1}
|
||||
43
Task/Long-year/ASIC/long-year.asic
Normal file
43
Task/Long-year/ASIC/long-year.asic
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
REM Long year
|
||||
CLS
|
||||
PRINT "**** List of ISO long years ****"
|
||||
PRINT "Start year";
|
||||
INPUT S
|
||||
PRINT "End year";
|
||||
INPUT E
|
||||
PRINT
|
||||
FOR Y = S TO E
|
||||
GOSUB CALCLY:
|
||||
IF LY <> 0 THEN
|
||||
PRINT Y;
|
||||
ENDIF
|
||||
NEXT Y
|
||||
PRINT
|
||||
END
|
||||
|
||||
CALCLY:
|
||||
REM Nonzero if Y is long
|
||||
LY = 0
|
||||
AY = Y
|
||||
GOSUB CALCWD:
|
||||
IF WD = 4 THEN
|
||||
LY = -1
|
||||
ENDIF
|
||||
AY = Y - 1
|
||||
GOSUB CALCWD:
|
||||
IF WD = 3 THEN
|
||||
LY = -1
|
||||
ENDIF
|
||||
RETURN
|
||||
|
||||
CALCWD:
|
||||
REM Weekday of AY-12-31, 0 = Sunday
|
||||
WD = AY
|
||||
TMP = AY / 4
|
||||
WD = WD + TMP
|
||||
TMP = AY / 100
|
||||
WD = WD - TMP
|
||||
TMP = AY / 400
|
||||
WD = WD + TMP
|
||||
WD = WD MOD 7
|
||||
RETURN
|
||||
31
Task/Long-year/AWK/long-year.awk
Normal file
31
Task/Long-year/AWK/long-year.awk
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# syntax: GAWK -f LONG_YEAR.AWK
|
||||
BEGIN {
|
||||
for (cc=19; cc<=21; cc++) {
|
||||
printf("%2d00-%2d99: ",cc,cc)
|
||||
for (yy=0; yy<=99; yy++) {
|
||||
ccyy = sprintf("%02d%02d",cc,yy)
|
||||
if (is_long_year(ccyy)) {
|
||||
printf("%4d ",ccyy)
|
||||
}
|
||||
}
|
||||
printf("\n")
|
||||
}
|
||||
#
|
||||
printf("\n%4d-%4d: ",by=1970,ey=2037)
|
||||
for (y=by; y<=ey; y++) {
|
||||
if (strftime("%V",mktime(sprintf("%d 12 28 0 0 0",y))) == 53) {
|
||||
printf("%4d ",y)
|
||||
}
|
||||
}
|
||||
printf("\n")
|
||||
exit(0)
|
||||
}
|
||||
function is_long_year(year, i) {
|
||||
for (i=0; i<=1; i++) {
|
||||
year -= i
|
||||
if ((year + int(year/4) - int(year/100) + int(year/400)) % 7 == 4-i) {
|
||||
return(1)
|
||||
}
|
||||
}
|
||||
return(0)
|
||||
}
|
||||
26
Task/Long-year/Action-/long-year.action
Normal file
26
Task/Long-year/Action-/long-year.action
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
BYTE FUNC P(CARD y)
|
||||
RETURN ((y+(y/4)-(y/100)+(y/400)) MOD 7)
|
||||
|
||||
BYTE FUNC IsLongYear(CARD y)
|
||||
IF P(y)=4 OR P(y-1)=3 THEN
|
||||
RETURN (1)
|
||||
FI
|
||||
RETURN (0)
|
||||
|
||||
PROC Main()
|
||||
CARD y
|
||||
BYTE LMARGIN=$52,oldLMARGIN
|
||||
|
||||
oldLMARGIN=LMARGIN
|
||||
LMARGIN=0 ;remove left margin on the screen
|
||||
Put(125) PutE() ;clear the screen
|
||||
|
||||
FOR y=1900 TO 2400
|
||||
DO
|
||||
IF IsLongYear(y) THEN
|
||||
PrintC(y) Put(32)
|
||||
FI
|
||||
OD
|
||||
|
||||
LMARGIN=oldLMARGIN ;restore left margin on the screen
|
||||
RETURN
|
||||
34
Task/Long-year/Ada/long-year.ada
Normal file
34
Task/Long-year/Ada/long-year.ada
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
-------------------------------------------------------------
|
||||
-- Calculate long years
|
||||
-- Reference: https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
|
||||
-------------------------------------------------------------
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Calendar; use Ada.Calendar;
|
||||
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
|
||||
|
||||
procedure Main is
|
||||
First_Day : Time;
|
||||
Last_Day : Time;
|
||||
package AC renames Ada.Calendar;
|
||||
type Counter is mod 10;
|
||||
Count : Counter := 0;
|
||||
begin
|
||||
for Yr in Year_Number loop
|
||||
|
||||
First_Day := AC.Time_Of (Year => Yr, Month => 1, Day => 1);
|
||||
Last_Day := AC.Time_Of (Year => Yr, Month => 12, Day => 31);
|
||||
|
||||
-- If Jan 1 is Thursday or Dec 31 is Thursday then
|
||||
-- the year is a long year
|
||||
|
||||
if Day_Of_Week (First_Day) = Thursday
|
||||
or else Day_Of_Week (Last_Day) = Thursday
|
||||
then
|
||||
if Count = 0 then
|
||||
New_Line;
|
||||
end if;
|
||||
Put (Yr'Image);
|
||||
Count := Count + 1;
|
||||
end if;
|
||||
end loop;
|
||||
end Main;
|
||||
18
Task/Long-year/AppleScript/long-year-1.applescript
Normal file
18
Task/Long-year/AppleScript/long-year-1.applescript
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
on isLongYear(y)
|
||||
-- ISO8601 weeks begin on Mondays and belong to the year in which they have the most days.
|
||||
-- A year which begins on a Thursday, or which begins on a Wednesday and is a leap year,
|
||||
-- has majority stakes in the weeks it overlaps at *both* ends and so has 53 weeks instead of 52.
|
||||
-- Leap years divisible by 400 begin on Saturdays and so don't so need to be considered in the leap year check.
|
||||
|
||||
tell (current date) to set {Jan1, its day, its month, its year} to {it, 1, January, y}
|
||||
set startWeekday to Jan1's weekday
|
||||
|
||||
return ((startWeekday is Thursday) or ((startWeekday is Wednesday) and (y mod 4 is 0) and (y mod 100 > 0)))
|
||||
end isLongYear
|
||||
|
||||
set longYears to {}
|
||||
repeat with y from 2001 to 2100
|
||||
if (isLongYear(y)) then set end of longYears to y
|
||||
end repeat
|
||||
|
||||
return longYears
|
||||
10
Task/Long-year/AppleScript/long-year-2.applescript
Normal file
10
Task/Long-year/AppleScript/long-year-2.applescript
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
on isLongYear(y)
|
||||
return (y mod 400 is in {4, 9, 15, 20, 26, 32, 37, 43, 48, 54, 60, 65, 71, 76, 82, 88, 93, 99, 105, 111, 116, 122, 128, 133, 139, 144, 150, 156, 161, 167, 172, 178, 184, 189, 195, 201, 207, 212, 218, 224, 229, 235, 240, 246, 252, 257, 263, 268, 274, 280, 285, 291, 296, 303, 308, 314, 320, 325, 331, 336, 342, 348, 353, 359, 364, 370, 376, 381, 387, 392, 398})
|
||||
end isLongYear
|
||||
|
||||
set longYears to {}
|
||||
repeat with y from 2001 to 2100
|
||||
if (isLongYear(y)) then set end of longYears to y
|
||||
end repeat
|
||||
|
||||
return longYears
|
||||
9
Task/Long-year/Applesoft-BASIC/long-year.basic
Normal file
9
Task/Long-year/Applesoft-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
10 DEF FN M7(N) = N - 7 * INT (N / 7)
|
||||
20 DEF FN WD(Y) = FN M7(Y + INT (Y / 4) - INT (Y / 100) + INT (Y / 400))
|
||||
30 DEF FN LY(Y) = (4 = FN WD(Y)) OR (3 = FN WD(Y - 1))
|
||||
40 HOME : INVERSE : PRINT "**** LIST OF ISO LONG YEARS ****": NORMAL
|
||||
50 INPUT "START YEAR? ";S
|
||||
60 INPUT "END YEAR? ";E
|
||||
70 PRINT : FOR Y = S TO E
|
||||
80 IF FN LY(Y) THEN PRINT S$Y;:S$ = " "
|
||||
90 NEXT Y
|
||||
10
Task/Long-year/Arturo/long-year.arturo
Normal file
10
Task/Long-year/Arturo/long-year.arturo
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
longYear?: function [year][
|
||||
date: to :date .format: "dd/MM/yyyy" ~"01/01/|year|"
|
||||
|
||||
or? date\Day = "Thursday"
|
||||
and? leap? year
|
||||
date\Day = "Wednesday"
|
||||
]
|
||||
|
||||
print "Years with 53 weeks between 2000 and 2100:"
|
||||
print select 2000..2100 => longYear?
|
||||
5
Task/Long-year/AutoHotkey/long-year-1.ahk
Normal file
5
Task/Long-year/AutoHotkey/long-year-1.ahk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Long_year(y) {
|
||||
A := Mod(y + floor(y/4) - floor(y/100) + floor(y/400), 7)
|
||||
y--, B := Mod(y + floor(y/4) - floor(y/100) + floor(y/400), 7)
|
||||
return A=4 || B=3
|
||||
}
|
||||
6
Task/Long-year/AutoHotkey/long-year-2.ahk
Normal file
6
Task/Long-year/AutoHotkey/long-year-2.ahk
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
loop, 100{
|
||||
y := 1999+A_Index
|
||||
res .= Long_year(y) ? Y " ": ""
|
||||
}
|
||||
MsgBox % "Long Years 2000-2100 : " res
|
||||
return
|
||||
12
Task/Long-year/BASIC256/long-year.basic
Normal file
12
Task/Long-year/BASIC256/long-year.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function p(y)
|
||||
return (y + int(y/4) - int(y/100) + int(y/400)) mod 7
|
||||
end function
|
||||
|
||||
function isLongYear(y)
|
||||
return (p(y) = 4) or (p(y - 1) = 3)
|
||||
end function
|
||||
|
||||
for y = 2000 to 2100
|
||||
if isLongYear(y) then print y
|
||||
next y
|
||||
end
|
||||
20
Task/Long-year/BBC-BASIC/long-year.basic
Normal file
20
Task/Long-year/BBC-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
INSTALL @lib$ + "DATELIB"
|
||||
|
||||
REM The function as per specification.
|
||||
DEF FNLongYear(year%)=FN_dow(FN_mjd(1, 1, year%)) == 4 OR FN_dow(FN_mjd(31, 12, year%)) == 4
|
||||
|
||||
REM Demonstrating its use.
|
||||
PROCPrintLongYearsInCentury(20)
|
||||
PROCPrintLongYearsInCentury(21)
|
||||
PROCPrintLongYearsInCentury(22)
|
||||
END
|
||||
|
||||
DEF PROCPrintLongYearsInCentury(century%)
|
||||
LOCAL year%, start%
|
||||
start%=century% * 100 - 100
|
||||
PRINT "The long years between ";start% " and ";start% + 100 " are ";
|
||||
FOR year%=start% TO start% + 99
|
||||
IF FNLongYear(year%) PRINT STR$year% + " ";
|
||||
NEXT
|
||||
PRINT
|
||||
ENDPROC
|
||||
8
Task/Long-year/BCPL/long-year.bcpl
Normal file
8
Task/Long-year/BCPL/long-year.bcpl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
get "libhdr"
|
||||
|
||||
let p(y) = (y + y/4 - y/100 + y/400) rem 7
|
||||
let longyear(y) = p(y)=4 | p(y-1)=3
|
||||
|
||||
let start() be
|
||||
for y = 2000 to 2100
|
||||
if longyear(y) do writef("%N*N", y)
|
||||
30
Task/Long-year/C++/long-year.cpp
Normal file
30
Task/Long-year/C++/long-year.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Reference:
|
||||
// https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
|
||||
|
||||
#include <iostream>
|
||||
|
||||
inline int p(int year) {
|
||||
return (year + (year/4) - (year/100) + (year/400)) % 7;
|
||||
}
|
||||
|
||||
bool is_long_year(int year) {
|
||||
return p(year) == 4 || p(year - 1) == 3;
|
||||
}
|
||||
|
||||
void print_long_years(int from, int to) {
|
||||
for (int year = from, count = 0; year <= to; ++year) {
|
||||
if (is_long_year(year)) {
|
||||
if (count > 0)
|
||||
std::cout << ((count % 10 == 0) ? '\n' : ' ');
|
||||
std::cout << year;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Long years between 1800 and 2100:\n";
|
||||
print_long_years(1800, 2100);
|
||||
std::cout << '\n';
|
||||
return 0;
|
||||
}
|
||||
18
Task/Long-year/C-sharp/long-year.cs
Normal file
18
Task/Long-year/C-sharp/long-year.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using static System.Console;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
WriteLine("Long years in the 21st century:");
|
||||
WriteLine(string.Join(" ", 2000.To(2100).Where(y => ISOWeek.GetWeeksInYear(y) == 53)));
|
||||
}
|
||||
|
||||
public static IEnumerable<int> To(this int start, int end) {
|
||||
for (int i = start; i < end; i++) yield return i;
|
||||
}
|
||||
|
||||
}
|
||||
28
Task/Long-year/C/long-year.c
Normal file
28
Task/Long-year/C/long-year.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
// https://webspace.science.uu.nl/~gent0113/calendar/isocalendar.htm
|
||||
|
||||
int p(int year) {
|
||||
return (int)((double)year + floor(year/4) - floor(year/100) + floor(year/400)) % 7;
|
||||
}
|
||||
|
||||
int is_long_year(int year) {
|
||||
return p(year) == 4 || p(year - 1) == 3;
|
||||
}
|
||||
|
||||
void print_long_years(int from, int to) {
|
||||
for (int year = from; year <= to; ++year) {
|
||||
if (is_long_year(year)) {
|
||||
printf("%d ", year);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
printf("Long (53 week) years between 1800 and 2100\n\n");
|
||||
print_long_years(1800, 2100);
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
24
Task/Long-year/CLU/long-year.clu
Normal file
24
Task/Long-year/CLU/long-year.clu
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
% We can't hide one procedure inside another, but
|
||||
% we can hide the helper `p' in a cluster
|
||||
|
||||
longyear = cluster is test
|
||||
rep = null
|
||||
|
||||
p = proc (n: int) returns (int)
|
||||
return ((n + n/4 - n/100 + n/400) // 7)
|
||||
end p
|
||||
|
||||
test = proc (y: int) returns (bool)
|
||||
return (p(y)=4 | p(y-1)=3)
|
||||
end test
|
||||
end longyear
|
||||
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
|
||||
for i: int in int$from_to(2000, 2100) do
|
||||
if longyear$test(i) then
|
||||
stream$putl(po, int$unparse(i))
|
||||
end
|
||||
end
|
||||
end start_up
|
||||
14
Task/Long-year/Chipmunk-Basic/long-year.basic
Normal file
14
Task/Long-year/Chipmunk-Basic/long-year.basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
10 cls
|
||||
20 rem WD(Y) = WEEKDAY OF Y-12-31, 0 = SUNDAY
|
||||
30 def fnwd(Y) = (Y + INT(Y / 4) - INT(Y / 100) + INT(Y / 400)) mod 7
|
||||
40 rem LY(Y) = NONZERO IF Y IS LONG
|
||||
50 def fnly(Y) = (4 = FNWD(Y)) OR (3 = FNWD(Y-1))
|
||||
60 print "**** LIST OF ISO LONG YEARS ****"
|
||||
70 input "START YEAR? ",s
|
||||
80 input "END YEAR? ",e
|
||||
90 print
|
||||
100 for y = s to e
|
||||
110 if fn ly(y) then print y,
|
||||
120 next y
|
||||
130 print
|
||||
140 end
|
||||
6
Task/Long-year/Clojure/long-year.clj
Normal file
6
Task/Long-year/Clojure/long-year.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(defn long-year? [year]
|
||||
(-> (java.time.LocalDate/of year 12 28)
|
||||
(.get (.weekOfYear (java.time.temporal.WeekFields/ISO)))
|
||||
(= 53)))
|
||||
|
||||
(filter long-year? (range 2000 2100))
|
||||
18
Task/Long-year/Commodore-BASIC/long-year-1.basic
Normal file
18
Task/Long-year/Commodore-BASIC/long-year-1.basic
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
100 REM M7(N) = N MOD 7
|
||||
110 DEF FNM7(N) = N - 7*INT(N / 7)
|
||||
120 :
|
||||
130 REM WD(Y) = WEEKDAY OF Y-12-31, 0 = SUNDAY
|
||||
140 DEF FNWD(Y) = FNM7(Y + INT(Y / 4) - INT(Y / 100) + INT(Y / 400))
|
||||
150 :
|
||||
160 REM LY(Y) = NONZERO IF Y IS LONG
|
||||
170 DEF FNLY(Y) = (4 = FNWD(Y)) OR (3 = FNWD(Y-1))
|
||||
180 :
|
||||
190 PRINT CHR$(147); CHR$(18); "**** LIST OF ISO LONG YEARS ****"
|
||||
200 INPUT "START YEAR"; S
|
||||
210 INPUT "END YEAR"; E
|
||||
220 PRINT
|
||||
230 :
|
||||
240 FOR Y = S TO E
|
||||
250 : IF FNLY(Y) THEN PRINT Y,
|
||||
260 NEXT Y
|
||||
270 PRINT
|
||||
13
Task/Long-year/Commodore-BASIC/long-year-2.basic
Normal file
13
Task/Long-year/Commodore-BASIC/long-year-2.basic
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
function p(y as unsigned integer) as unsigned integer
|
||||
return ( y + int(y/4) - int(y/100) + int(y/400) ) mod 7
|
||||
end function
|
||||
|
||||
function islongyear( y as uinteger ) as boolean
|
||||
if p(y) = 4 then return true
|
||||
if p(y-1) = 3 then return true
|
||||
return false
|
||||
end function
|
||||
|
||||
print islongyear(1998)
|
||||
print islongyear(2020)
|
||||
print islongyear(2021)
|
||||
8
Task/Long-year/Common-Lisp/long-year.lisp
Normal file
8
Task/Long-year/Common-Lisp/long-year.lisp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(defun december-31-weekday (year)
|
||||
(mod (+ year (floor year 4) (- (floor year 100)) (floor year 400)) 7))
|
||||
|
||||
(defun iso-long-year-p (year)
|
||||
(or (= 4 (december-31-weekday year)) (= 3 (december-31-weekday (1- year)))))
|
||||
|
||||
(format t "Long years between 1800 and 2100:~&~a~%"
|
||||
(loop for y from 1800 to 2100 if (iso-long-year-p y) collect y))
|
||||
55
Task/Long-year/Dc/long-year.dc
Normal file
55
Task/Long-year/Dc/long-year.dc
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
[0q]s0
|
||||
[1q]s1
|
||||
[1r- r 1r- * 1r-]sO # O = logical OR
|
||||
##.............................................................................
|
||||
# C: for( initcode ; condcode ; incrcode ) {body}
|
||||
# .[q] [1] [2] [3] [4]
|
||||
# # [initcode] [condcode] [incrcode] [body] (for)
|
||||
[ [q]S. 4:.3:.2:.x [2;.x 0=. 4;.x 3;.x 0;.x]d0:.x
|
||||
Os.L.o
|
||||
]sF # F = for
|
||||
##.............................................................................
|
||||
# [1] [0]
|
||||
# (.) [cond_code] [then_code] [else_code] (if_CTE)
|
||||
[ []S. 0:. 1:. x [0=0 1]x ;. s.L. x]sI # I = if
|
||||
##-----------------------------------------------------------------------------
|
||||
[S. l. l.4/+ l.100/- l.400/+ 7% s.L.]sp # p
|
||||
##.............................................................................
|
||||
[S. [l. lpx 4=1 0]x
|
||||
[l. 1- lpx 3=1 0]x lOx
|
||||
s.L.
|
||||
]si # i = is_long_year
|
||||
##.............................................................................
|
||||
[
|
||||
# f = from
|
||||
# t = to
|
||||
# y = year
|
||||
# c = count
|
||||
st sf # fetch args from stack
|
||||
[lfsy 0sc]
|
||||
[ly lt <0 1] # cond
|
||||
[ly 1+ sy] # incr y
|
||||
[
|
||||
[ly lix] # is_long_year(y)
|
||||
[
|
||||
[lc 0 <1 0] # 0<c
|
||||
[
|
||||
[ lc 10% 0=1 0] # (c % 10) == 0
|
||||
[ AP ]
|
||||
[ [ ]P ]
|
||||
lIx # if
|
||||
]
|
||||
[]
|
||||
lIx # if
|
||||
ly n
|
||||
lc 1+ sc
|
||||
]
|
||||
[]
|
||||
lIx # if
|
||||
] lFx # for
|
||||
]sD # D = doit = print_long_years
|
||||
##.............................................................................
|
||||
|
||||
[Long years between 1800 and 2100:]P AP
|
||||
1800 2100 lDx
|
||||
AP
|
||||
42
Task/Long-year/Delphi/long-year.delphi
Normal file
42
Task/Long-year/Delphi/long-year.delphi
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
program Long_year;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
{$R *.res}
|
||||
|
||||
uses
|
||||
System.SysUtils;
|
||||
|
||||
function p(const Year: Integer): Integer;
|
||||
begin
|
||||
Result := (Year + (Year div 4) - (Year div 100) + (Year div 400)) mod 7;
|
||||
end;
|
||||
|
||||
function IsLongYear(const Year: Integer): Boolean;
|
||||
begin
|
||||
Result := (p(Year) = 4) or (p(Year - 1) = 3);
|
||||
end;
|
||||
|
||||
procedure PrintLongYears(const StartYear: Integer; const EndYear: Integer);
|
||||
var
|
||||
Year, Count: Integer;
|
||||
begin
|
||||
Count := 0;
|
||||
for Year := 1800 to 2100 do
|
||||
if IsLongYear(Year) then
|
||||
begin
|
||||
if Count mod 10 = 0 then
|
||||
Writeln;
|
||||
Write(Year, ' ');
|
||||
inc(Count);
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
Year: Integer;
|
||||
|
||||
begin
|
||||
Writeln('Long years between 1800 and 2100:');
|
||||
PrintLongYears(1800, 2100);
|
||||
Readln;
|
||||
end.
|
||||
9
Task/Long-year/Elixir/long-year.elixir
Normal file
9
Task/Long-year/Elixir/long-year.elixir
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
defmodule ISO do
|
||||
def long_year?(y) do
|
||||
{:ok, jan1} = Date.new(y,1,1)
|
||||
{:ok, dec31} = Date.new(y,12,31)
|
||||
Date.day_of_week(jan1) == 4 or Date.day_of_week(dec31) == 4
|
||||
end
|
||||
end
|
||||
|
||||
IO.inspect(Enum.filter(1990..2050, &ISO.long_year?/1))
|
||||
6
Task/Long-year/Factor/long-year.factor
Normal file
6
Task/Long-year/Factor/long-year.factor
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
USING: calendar formatting io kernel math.ranges sequences ;
|
||||
|
||||
: long-year? ( n -- ? ) 12 28 <date> week-number 53 = ;
|
||||
|
||||
"Year Long?\n-----------" print 1990 2021 [a,b]
|
||||
[ dup long-year? "yes" "no" ? "%d %s\n" printf ] each
|
||||
3
Task/Long-year/Forth/long-year.fth
Normal file
3
Task/Long-year/Forth/long-year.fth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
: dec31wd ( year -- weekday ) dup dup 4 / swap dup 100 / swap 400 / swap - + + 7 mod ;
|
||||
: long? ( year -- flag ) dup dec31wd 4 = if drop 1 else 1 - dec31wd 3 = if 1 else 0 then then ;
|
||||
: demo ( startyear endyear -- ) cr swap do i long? if i . then loop cr ;
|
||||
37
Task/Long-year/Fortran/long-year.f
Normal file
37
Task/Long-year/Fortran/long-year.f
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
program longyear
|
||||
use iso_fortran_env, only: output_unit, input_unit
|
||||
implicit none
|
||||
|
||||
integer :: start, ende, i, counter
|
||||
integer, parameter :: line_break=10
|
||||
|
||||
write(output_unit,*) "Enter beginning of interval"
|
||||
read(input_unit,*) start
|
||||
write(output_unit,*) "Enter end of interval"
|
||||
read(input_unit,*) ende
|
||||
|
||||
if (start>=ende) error stop "Last year must be after first year!"
|
||||
|
||||
counter = 0
|
||||
do i = start, ende
|
||||
if (is_long_year(i)) then
|
||||
write(output_unit,'(I0,x)', advance="no") i
|
||||
counter = counter + 1
|
||||
if (modulo(counter,line_break) == 0) write(output_unit,*)
|
||||
end if
|
||||
end do
|
||||
contains
|
||||
pure function p(year)
|
||||
integer, intent(in) :: year
|
||||
integer :: p
|
||||
|
||||
p = modulo(year + year/4 - year/100 + year/400, 7)
|
||||
end function p
|
||||
|
||||
pure function is_long_year(year)
|
||||
integer, intent(in) :: year
|
||||
logical :: is_long_year
|
||||
|
||||
is_long_year = p(year) == 4 .or. p(year-1) == 3
|
||||
end function is_long_year
|
||||
end program longyear
|
||||
33
Task/Long-year/Free-Pascal/long-year.pas
Normal file
33
Task/Long-year/Free-Pascal/long-year.pas
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
program Long_year;
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
DateUtils;
|
||||
|
||||
procedure PrintLongYears(StartYear, EndYear: Uint32);
|
||||
var
|
||||
Year, Count: Uint32;
|
||||
DateSep: char;
|
||||
begin
|
||||
DateSep := FormatSettings.DateSeparator;
|
||||
Writeln('Long years between ', StartYear, ' and ', EndYear);
|
||||
Count := 0;
|
||||
for Year := StartYear to EndYear do
|
||||
if WeeksInYear(StrToDate('01' + DateSep + '01' + DateSep + IntToStr(Year))) = 53 then
|
||||
begin
|
||||
if Count mod 10 = 0 then
|
||||
Writeln;
|
||||
Write(Year, ' ');
|
||||
Inc(Count);
|
||||
end;
|
||||
if Count mod 10 <> 0 then
|
||||
Writeln;
|
||||
writeln('Found ', Count, ' long years between ', StartYear, ' and ', EndYear);
|
||||
end;
|
||||
|
||||
begin
|
||||
PrintLongYears(1800, 2100);
|
||||
{$IFDEF WINDOWS}
|
||||
Readln;
|
||||
{$ENDIF}
|
||||
end.
|
||||
12
Task/Long-year/GW-BASIC/long-year.basic
Normal file
12
Task/Long-year/GW-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
10 INPUT "Enter a year: ", Y
|
||||
20 X = Y
|
||||
30 GOSUB 100
|
||||
40 IF P = 4 THEN L = 1
|
||||
50 X = Y - 1
|
||||
60 GOSUB 100
|
||||
70 IF P = 3 THEN L = 1
|
||||
80 IF L = 1 THEN PRINT Y; " is a long year." ELSE PRINT Y;" is not a long year."
|
||||
90 END
|
||||
100 P = X + INT(X/4) - INT(X/100) + INT(X/400)
|
||||
110 P = P MOD 7
|
||||
120 RETURN
|
||||
21
Task/Long-year/Gambas/long-year.gambas
Normal file
21
Task/Long-year/Gambas/long-year.gambas
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
Public Sub Main()
|
||||
|
||||
For y As Integer = 2000 To 2100
|
||||
If isLongYear(y) Then Print y,
|
||||
Next
|
||||
|
||||
End
|
||||
|
||||
Function p(y As Integer) As Integer
|
||||
|
||||
Return (y + (y \ 4) - (y \ 100) + (y \ 400)) Mod 7
|
||||
|
||||
End Function
|
||||
|
||||
Function isLongYear(y As Integer) As Boolean
|
||||
|
||||
If p(y) = 4 Then Return True
|
||||
If p(y - 1) = 3 Then Return True
|
||||
Return False
|
||||
|
||||
End Function
|
||||
22
Task/Long-year/Go/long-year.go
Normal file
22
Task/Long-year/Go/long-year.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
centuries := []string{"20th", "21st", "22nd"}
|
||||
starts := []int{1900, 2000, 2100}
|
||||
for i := 0; i < len(centuries); i++ {
|
||||
var longYears []int
|
||||
fmt.Printf("\nLong years in the %s century:\n", centuries[i])
|
||||
for j := starts[i]; j < starts[i] + 100; j++ {
|
||||
t := time.Date(j, time.December, 28, 0, 0, 0, 0, time.UTC)
|
||||
if _, week := t.ISOWeek(); week == 53 {
|
||||
longYears = append(longYears, j)
|
||||
}
|
||||
}
|
||||
fmt.Println(longYears)
|
||||
}
|
||||
}
|
||||
10
Task/Long-year/Haskell/long-year.hs
Normal file
10
Task/Long-year/Haskell/long-year.hs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import Data.Time.Calendar (fromGregorian)
|
||||
import Data.Time.Calendar.WeekDate (toWeekDate)
|
||||
|
||||
longYear :: Integer -> Bool
|
||||
longYear y =
|
||||
let (_, w, _) = toWeekDate $ fromGregorian y 12 28
|
||||
in 52 < w
|
||||
|
||||
main :: IO ()
|
||||
main = mapM_ print $ filter longYear [2000 .. 2100]
|
||||
9
Task/Long-year/IS-BASIC/long-year.basic
Normal file
9
Task/Long-year/IS-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
100 PROGRAM "Longyear.bas"
|
||||
110 DEF RD(Y)=Y*365+INT(Y/4)-INT(Y/100)+INT(Y/400)
|
||||
120 DEF LONGYEAR(Y)=(4=MOD(RD(Y),7)) OR(4=MOD((RD(Y-1)+1),7))
|
||||
130 INPUT PROMPT "Start year: ":S
|
||||
140 INPUT PROMPT "End year: ":E
|
||||
150 FOR Y=S TO E
|
||||
160 IF LONGYEAR(Y) THEN PRINT Y,
|
||||
170 NEXT
|
||||
180 PRINT
|
||||
3
Task/Long-year/J/long-year.j
Normal file
3
Task/Long-year/J/long-year.j
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
p =: 1 4 _100 400&(7 | [: <. +/ @: %~)"1 0
|
||||
ily =: (4=p) +. 3=p@:<:
|
||||
ply =: (#~ ily)@:([ + 1+i.@:-~)
|
||||
19
Task/Long-year/Java/long-year.java
Normal file
19
Task/Long-year/Java/long-year.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import java.time.LocalDate;
|
||||
import java.time.temporal.WeekFields;
|
||||
|
||||
public class LongYear {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.printf("Long years this century:%n");
|
||||
for (int year = 2000 ; year < 2100 ; year++ ) {
|
||||
if ( longYear(year) ) {
|
||||
System.out.print(year + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean longYear(int year) {
|
||||
return LocalDate.of(year, 12, 28).get(WeekFields.ISO.weekOfYear()) == 53;
|
||||
}
|
||||
|
||||
}
|
||||
11
Task/Long-year/JavaScript/long-year.js
Normal file
11
Task/Long-year/JavaScript/long-year.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
const isLongYear = (year) => {
|
||||
const jan1 = new Date(year, 0, 1);
|
||||
const dec31 = new Date(year, 11, 31);
|
||||
return (4 == jan1.getDay() || 4 == dec31.getDay())
|
||||
}
|
||||
|
||||
for (let y = 1995; y <= 2045; y++) {
|
||||
if (isLongYear(y)) {
|
||||
console.log(y)
|
||||
}
|
||||
}
|
||||
25
Task/Long-year/Jq/long-year-1.jq
Normal file
25
Task/Long-year/Jq/long-year-1.jq
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# 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(", "))
|
||||
16
Task/Long-year/Jq/long-year-2.jq
Normal file
16
Task/Long-year/Jq/long-year-2.jq
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# 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_per_gmtime($year; $month; $day):
|
||||
[$year, $month - 1, $day, 0, 0, 1, 0, 0] | mktime | gmtime | .[-2];
|
||||
|
||||
# 4 corresponds to Thursday
|
||||
def has53weeks:
|
||||
day_of_week_per_gmtime(.; 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(", "))
|
||||
8
Task/Long-year/Julia/long-year.julia
Normal file
8
Task/Long-year/Julia/long-year.julia
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using Dates
|
||||
|
||||
has53weeks(year) = week(Date(year, 12, 28)) == 53
|
||||
|
||||
println(" Year 53 weeks?\n----------------")
|
||||
for year in 1990:2021
|
||||
println(year, " ", has53weeks(year) ? "Yes" : "No")
|
||||
end
|
||||
6
Task/Long-year/Kotlin/long-year.kotlin
Normal file
6
Task/Long-year/Kotlin/long-year.kotlin
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
fun main() {
|
||||
val has53Weeks = { year: Int -> LocalDate.of(year, 12, 28).get(WeekFields.ISO.weekOfYear()) == 53 }
|
||||
println("Long years this century:")
|
||||
(2000..2100).filter(has53Weeks)
|
||||
.forEach { year -> print("$year ")}
|
||||
}
|
||||
13
Task/Long-year/Logo/long-year.logo
Normal file
13
Task/Long-year/Logo/long-year.logo
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
to div :x :y
|
||||
output int quotient :x :y
|
||||
end
|
||||
|
||||
to dec31_weekday :year
|
||||
output remainder (sum :year div :year 4 div :year -100 div :year 400) 7
|
||||
end
|
||||
|
||||
to iso_long_year? :year
|
||||
output or 4 = dec31_weekday :year 3 = dec31_weekday difference :year 1
|
||||
end
|
||||
|
||||
for [y 1995 2045 1] [if iso_long_year? :y [print :y]]
|
||||
14
Task/Long-year/MSX-Basic/long-year.basic
Normal file
14
Task/Long-year/MSX-Basic/long-year.basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
10 CLS
|
||||
20 REM WD(Y) = WEEKDAY OF Y-12-31, 0 = SUNDAY
|
||||
30 DEF FNWD(Y) = (Y + INT(Y/4) - INT(Y/100) + INT(Y/400)) MOD 7
|
||||
40 REM LY(Y) = NONZERO IF Y IS LONG
|
||||
50 DEF FNLY(Y) = (4 = FNWD(Y)) OR (3 = FNWD(Y-1))
|
||||
60 PRINT "*** LIST OF ISO LONG YEARS ***"
|
||||
70 INPUT "START YEAR ";S
|
||||
80 INPUT " END YEAR ";E
|
||||
90 PRINT
|
||||
100 FOR Y = S TO E
|
||||
110 IF FNLY(Y) THEN PRINT Y,
|
||||
120 NEXT Y
|
||||
130 PRINT
|
||||
140 END
|
||||
9
Task/Long-year/Mathematica/long-year.math
Normal file
9
Task/Long-year/Mathematica/long-year.math
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
firstyear = 2000;
|
||||
lastyear = 2099;
|
||||
years = Range[firstyear, lastyear];
|
||||
firstday = Table[DayName[{years[[n]], 01, 01}], {n, Length[years]}];
|
||||
lastday = Table[DayName[{years[[n]], 12, 31}], {n, Length[years]}];
|
||||
Table[If[years[[n]] >= 1582,
|
||||
If[firstday[[n]] == Thursday || lastday[[n]] == Thursday,
|
||||
Style[years[[n]] " long year \n", Bold, Red] ,
|
||||
years[[n]] " short \n"], "error \n"], {n, Length[years]}]
|
||||
22
Task/Long-year/Modula-2/long-year.mod2
Normal file
22
Task/Long-year/Modula-2/long-year.mod2
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
MODULE LongYear;
|
||||
FROM InOut IMPORT WriteCard, WriteLn;
|
||||
|
||||
VAR year: CARDINAL;
|
||||
|
||||
PROCEDURE isLongYear(year: CARDINAL): BOOLEAN;
|
||||
PROCEDURE p(year: CARDINAL): CARDINAL;
|
||||
BEGIN
|
||||
RETURN (year + year DIV 4 - year DIV 100 + year DIV 400) MOD 7;
|
||||
END p;
|
||||
BEGIN
|
||||
RETURN (p(year) = 4) OR (p(year-1) = 3);
|
||||
END isLongYear;
|
||||
|
||||
BEGIN
|
||||
FOR year := 2000 TO 2100 DO
|
||||
IF isLongYear(year) THEN
|
||||
WriteCard(year, 4);
|
||||
WriteLn;
|
||||
END;
|
||||
END;
|
||||
END LongYear.
|
||||
20
Task/Long-year/Nascom-BASIC/long-year.basic
Normal file
20
Task/Long-year/Nascom-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
10 REM Long year
|
||||
20 REM FNM7(N)=MOD(N,7)
|
||||
30 DEF FNM7(N)=N-7*INT(N/7)
|
||||
40 REM FNWD(Y)=Weekday of Y-12-31, 0 Sunday
|
||||
50 DEF FND(Y)=Y+INT(Y/4)-INT(Y/100)+INT(Y/400)
|
||||
60 DEF FNWD(Y)=FNM7(FND(Y))
|
||||
70 REM FNLY(Y)=Nonzero if Y is long
|
||||
80 DEF FNLY(Y)=(4=FNWD(Y))OR(3=FNWD(Y-1))
|
||||
90 CLS
|
||||
100 PRINT "**** ";
|
||||
110 PRINT "List of ISO long years";
|
||||
120 PRINT " ****"
|
||||
130 INPUT "Start year";S
|
||||
140 INPUT "End year";E
|
||||
150 PRINT
|
||||
160 FOR Y=S TO E
|
||||
170 IF FNLY(Y) THEN PRINT Y;
|
||||
180 NEXT Y
|
||||
190 PRINT
|
||||
200 END
|
||||
11
Task/Long-year/Nim/long-year.nim
Normal file
11
Task/Long-year/Nim/long-year.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import times
|
||||
|
||||
proc has53weeks(year: Positive): bool =
|
||||
let dt = initDateTime(monthday = 1, month = mJan, year = year, hour = 0, minute = 0, second= 0)
|
||||
result = dt.weekday == dThu or year.isLeapYear and dt.weekday == dWed
|
||||
|
||||
when isMainModule:
|
||||
echo "Years with 53 weeks between 2000 and 2100:"
|
||||
for year in 2000..2100:
|
||||
if year.has53weeks:
|
||||
echo year
|
||||
9
Task/Long-year/PHP/long-year.php
Normal file
9
Task/Long-year/PHP/long-year.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function isLongYear($year) {
|
||||
return (53 == strftime('%V', gmmktime(0,0,0,12,28,$year)));
|
||||
}
|
||||
|
||||
for ($y=1995; $y<=2045; ++$y) {
|
||||
if (isLongYear($y)) {
|
||||
printf("%s\n", $y);
|
||||
}
|
||||
}
|
||||
29
Task/Long-year/PL-0/long-year.pl0
Normal file
29
Task/Long-year/PL-0/long-year.pl0
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
var startyear, endyear, year, longyear, ayear, weekday;
|
||||
|
||||
procedure calcweekday;
|
||||
begin
|
||||
weekday := ayear + ayear / 4 - ayear / 100 + ayear / 400;
|
||||
weekday := weekday - (weekday / 7) * 7
|
||||
end;
|
||||
|
||||
procedure calclongyear;
|
||||
begin
|
||||
longyear := 0; ayear := year;
|
||||
call calcweekday;
|
||||
if weekday = 4 then longyear := 1;
|
||||
ayear := year - 1;
|
||||
call calcweekday;
|
||||
if weekday = 3 then longyear := 1
|
||||
end;
|
||||
|
||||
begin
|
||||
? startyear;
|
||||
? endyear;
|
||||
year := startyear;
|
||||
while year <= endyear do
|
||||
begin
|
||||
call calclongyear;
|
||||
if longyear <> 0 then ! year;
|
||||
year := year + 1
|
||||
end
|
||||
end.
|
||||
24
Task/Long-year/Palo-Alto-Tiny-BASIC/long-year.basic
Normal file
24
Task/Long-year/Palo-Alto-Tiny-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
10 REM LONG YEAR
|
||||
20 PRINT "*** LIST OF ISO LONG YEARS ***"
|
||||
30 INPUT "START YEAR"B
|
||||
40 INPUT "END YEAR"E
|
||||
50 FOR Y=B TO E
|
||||
60 GOSUB 200
|
||||
70 IF L#0 PRINT Y," ",
|
||||
80 NEXT Y
|
||||
90 PRINT
|
||||
100 STOP
|
||||
190 REM L NONZERO IF Y IS LONG
|
||||
200 LET L=0,J=Y
|
||||
210 GOSUB 400
|
||||
220 IF W=4 LET L=1
|
||||
230 LET J=Y-1
|
||||
240 GOSUB 400
|
||||
250 IF W=3 LET L=1
|
||||
260 RETURN
|
||||
370 REM CALCULATE DAY OF WEEK W GIVEN
|
||||
380 REM OF J-12-31, GIVEN YEAR J
|
||||
390 REM SUNDAY = 0, SATURDAY = 6
|
||||
400 LET W=J+J/4-J/100+J/400
|
||||
410 LET W=W-(W/7)*7
|
||||
420 RETURN
|
||||
35
Task/Long-year/Pascal/long-year.pas
Normal file
35
Task/Long-year/Pascal/long-year.pas
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
program long_year(input);
|
||||
var
|
||||
y: integer;
|
||||
|
||||
function rd_dec31(year: integer): integer;
|
||||
begin
|
||||
{ Rata Die of Dec 31, year }
|
||||
rd_dec31 := year * 365 + year div 4 - year div 100 + year div 400
|
||||
end;
|
||||
|
||||
function rd_jan1(year: integer): integer;
|
||||
begin
|
||||
rd_jan1 := rd_dec31(year - 1) + 1
|
||||
end;
|
||||
|
||||
function weekday(rd: integer): integer;
|
||||
begin
|
||||
weekday := rd mod 7;
|
||||
end;
|
||||
|
||||
function long_year(year: integer): boolean;
|
||||
var
|
||||
jan1: integer;
|
||||
dec31: integer;
|
||||
begin
|
||||
jan1 := rd_jan1(year);
|
||||
dec31 := rd_dec31(year);
|
||||
long_year := (weekday(jan1) = 4) or (weekday(dec31) = 4)
|
||||
end;
|
||||
|
||||
begin
|
||||
for y := 1990 to 2050 do
|
||||
if long_year(y) then
|
||||
writeln(y)
|
||||
end.
|
||||
10
Task/Long-year/Perl/long-year.pl
Normal file
10
Task/Long-year/Perl/long-year.pl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use DateTime;
|
||||
|
||||
for my $century (19 .. 21) {
|
||||
for my $year ($century*100 .. ++$century*100 - 1) {
|
||||
print "$year " if DateTime->new(year => $year, month => 12, day => 28)->week_number > 52
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
20
Task/Long-year/Phix/long-year.phix
Normal file
20
Task/Long-year/Phix/long-year.phix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">week_number</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">doy</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">day_of_year</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">),</span>
|
||||
<span style="color: #000000;">dow</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">day_of_week</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">),</span>
|
||||
<span style="color: #000000;">week</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">doy</span><span style="color: #0000FF;">-</span><span style="color: #000000;">dow</span><span style="color: #0000FF;">+</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">7</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">week</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #000000;">20</span> <span style="color: #008080;">to</span> <span style="color: #000000;">22</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">long_years</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">century</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">100</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">=</span><span style="color: #000000;">century</span> <span style="color: #008080;">to</span> <span style="color: #000000;">century</span><span style="color: #0000FF;">+</span><span style="color: #000000;">99</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">week_number</span><span style="color: #0000FF;">(</span><span style="color: #000000;">year</span><span style="color: #0000FF;">,</span><span style="color: #000000;">12</span><span style="color: #0000FF;">,</span><span style="color: #000000;">28</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">53</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">long_years</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">year</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Long years in the %d%s century:%v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">),</span><span style="color: #000000;">long_years</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<!--
|
||||
10
Task/Long-year/PowerShell/long-year.psh
Normal file
10
Task/Long-year/PowerShell/long-year.psh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Function Is-Long-Year {
|
||||
param([Int]$year)
|
||||
53 -eq (Get-Date -Year $year -Month 12 -Day 28 -UFormat %V)
|
||||
}
|
||||
|
||||
For ($y=1995; $y -le 2045; $y++) {
|
||||
If (Is-Long-Year $y) {
|
||||
Write-Host $y
|
||||
}
|
||||
}
|
||||
38
Task/Long-year/Prolog/long-year.pro
Normal file
38
Task/Long-year/Prolog/long-year.pro
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
% See https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
|
||||
|
||||
p(Year, P):-
|
||||
P is (Year + (Year//4) - (Year//100) + (Year//400)) mod 7.
|
||||
|
||||
long_year(Year):-
|
||||
p(Year, 4),
|
||||
!.
|
||||
long_year(Year):-
|
||||
Year_before is Year - 1,
|
||||
p(Year_before, 3).
|
||||
|
||||
print_long_years(From, To):-
|
||||
writef("Long years between %w and %w:\n", [From, To]),
|
||||
print_long_years(From, To, 0),
|
||||
nl.
|
||||
|
||||
print_long_years(From, To, _):-
|
||||
From > To,
|
||||
!.
|
||||
print_long_years(From, To, Count):-
|
||||
long_year(From),
|
||||
!,
|
||||
(Count > 0 ->
|
||||
(0 is Count mod 10 -> nl ; write(' '))
|
||||
;
|
||||
true
|
||||
),
|
||||
write(From),
|
||||
Count1 is Count + 1,
|
||||
Next is From + 1,
|
||||
print_long_years(Next, To, Count1).
|
||||
print_long_years(From, To, Count):-
|
||||
Next is From + 1,
|
||||
print_long_years(Next, To, Count).
|
||||
|
||||
main:-
|
||||
print_long_years(1800, 2100).
|
||||
18
Task/Long-year/PureBasic/long-year.basic
Normal file
18
Task/Long-year/PureBasic/long-year.basic
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Procedure.b p(y)
|
||||
ProcedureReturn (y + Int(y/4) - Int(y/100) + Int(y/400)) % 7
|
||||
EndProcedure
|
||||
|
||||
Procedure.b isLongYear(y)
|
||||
ProcedureReturn Bool((p(y) = 4) Or (p(y - 1) = 3))
|
||||
EndProcedure
|
||||
|
||||
If OpenConsole()
|
||||
For y = 2000 To 2100
|
||||
If isLongYear(y)
|
||||
PrintN(Str(y))
|
||||
EndIf
|
||||
Next y
|
||||
|
||||
Print(""): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
25
Task/Long-year/Python/long-year.py
Normal file
25
Task/Long-year/Python/long-year.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
'''Long Year ?'''
|
||||
|
||||
from datetime import date
|
||||
|
||||
|
||||
# longYear :: Year Int -> Bool
|
||||
def longYear(y):
|
||||
'''True if the ISO year y has 53 weeks.'''
|
||||
return 52 < date(y, 12, 28).isocalendar()[1]
|
||||
|
||||
|
||||
# --------------------------TEST---------------------------
|
||||
# main :: IO ()
|
||||
def main():
|
||||
'''Longer (53 week) years in the range 2000-2100'''
|
||||
for year in [
|
||||
x for x in range(2000, 1 + 2100)
|
||||
if longYear(x)
|
||||
]:
|
||||
print(year)
|
||||
|
||||
|
||||
# MAIN ---
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
9
Task/Long-year/Quackery/long-year.quackery
Normal file
9
Task/Long-year/Quackery/long-year.quackery
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[ dup dip
|
||||
[ 1 1 rot dayofweek 4 = ]
|
||||
31 12 rot dayofweek 4 = or ] is longyear ( n --> b )
|
||||
|
||||
say "Long Years in the 21st Century" cr
|
||||
cr
|
||||
100 times
|
||||
[ 2000 i^ + longyear if
|
||||
[ 2000 i^ + echo sp ] ]
|
||||
31
Task/Long-year/QuickBASIC/long-year.basic
Normal file
31
Task/Long-year/QuickBASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
DEFINT A-Z
|
||||
|
||||
DECLARE FUNCTION p% (Yr AS INTEGER)
|
||||
DECLARE FUNCTION LongYear% (Yr AS INTEGER)
|
||||
|
||||
DIM iYi, iYf, i
|
||||
|
||||
CLS
|
||||
PRINT "This program calculates which are 53-week years in a range."
|
||||
PRINT
|
||||
INPUT "Initial year"; iYi
|
||||
INPUT "Final year (could be the same)"; iYf
|
||||
IF iYf >= iYi THEN
|
||||
FOR i = iYi TO iYf
|
||||
IF LongYear(i) THEN
|
||||
PRINT i; " ";
|
||||
END IF
|
||||
NEXT i
|
||||
END IF
|
||||
PRINT
|
||||
PRINT
|
||||
PRINT "End of program."
|
||||
END
|
||||
|
||||
FUNCTION LongYear% (Yr AS INTEGER)
|
||||
LongYear% = (p%(Yr) = 4) OR (p%(Yr - 1) = 3)
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION p% (Yr AS INTEGER)
|
||||
p% = (Yr + INT(Yr / 4) - INT(Yr / 100) + INT(Yr / 400)) MOD 7
|
||||
END FUNCTION
|
||||
13
Task/Long-year/REXX/long-year.rexx
Normal file
13
Task/Long-year/REXX/long-year.rexx
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/*REXX program determines if a (calendar) year is a SHORT or LONG year (52 or 53 weeks).*/
|
||||
parse arg LO HI . /*obtain optional args. */
|
||||
if LO=='' | LO=="," | LO=='*' then LO= left( date('S'), 4) /*Not given? Use default.*/
|
||||
if HI=='' | HI=="," then HI= LO /* " " " " */
|
||||
if HI=='*' then HI= left( date('S'), 4) /*an asterisk ≡ current yr*/
|
||||
|
||||
do j=LO to HI /*process single yr or range of years.*/
|
||||
say ' year ' j " is a " right( word('short long', weeks(j)-51),5) " year"
|
||||
end /*j*/
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
pWeek: parse arg #; return (# + # % 4 - # % 100 + # % 400) // 7
|
||||
weeks: parse arg y; if pWeek(y)==4 | pWeek(y-1)==3 then return 53; return 52
|
||||
6
Task/Long-year/Raku/long-year.raku
Normal file
6
Task/Long-year/Raku/long-year.raku
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
sub is-long ($year) { Date.new("$year-12-28").week[1] == 53 }
|
||||
|
||||
# Testing
|
||||
say "Long years in the 20th century:\n", (1900..^2000).grep: &is-long;
|
||||
say "\nLong years in the 21st century:\n", (2000..^2100).grep: &is-long;
|
||||
say "\nLong years in the 22nd century:\n", (2100..^2200).grep: &is-long;
|
||||
9
Task/Long-year/Ring/long-year.ring
Normal file
9
Task/Long-year/Ring/long-year.ring
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
see "long years 2000-2099: "
|
||||
for year = 2000 to 2100
|
||||
num1 = (year-1900)%7
|
||||
num2 = floor((year-1904)/4)
|
||||
num3 = (num1+num2+5)%7
|
||||
if num3 = 0 or (num1 = 6 and num3 = 1)
|
||||
see "" + year + " "
|
||||
ok
|
||||
next
|
||||
7
Task/Long-year/Ruby/long-year.rb
Normal file
7
Task/Long-year/Ruby/long-year.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require 'date'
|
||||
|
||||
def long_year?(year = Date.today.year)
|
||||
Date.new(year, 12, 28).cweek == 53
|
||||
end
|
||||
|
||||
(2020..2030).each{|year| puts "#{year} is long? #{ long_year?(year) }." }
|
||||
12
Task/Long-year/Run-BASIC/long-year.basic
Normal file
12
Task/Long-year/Run-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function p(y)
|
||||
p = (y + int(y/4) - int(y/100) + int(y/400)) mod 7
|
||||
end function
|
||||
|
||||
function isLongYear(y)
|
||||
isLongYear = (p(y) = 4) or (p(y -1) = 3)
|
||||
end function
|
||||
|
||||
for y = 2000 to 2100
|
||||
if isLongYear(y) then print y
|
||||
next y
|
||||
end
|
||||
13
Task/Long-year/Rust/long-year.rust
Normal file
13
Task/Long-year/Rust/long-year.rust
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
extern crate time; // 0.2.16
|
||||
|
||||
use time::Date;
|
||||
|
||||
fn main() {
|
||||
(2000..=2099)
|
||||
.filter(|&year| is_long_year(year))
|
||||
.for_each(|year| println!("{}", year));
|
||||
}
|
||||
|
||||
fn is_long_year(year: i32) -> bool {
|
||||
Date::try_from_ymd(year, 12, 28).map_or(false, |date| date.week() == 53)
|
||||
}
|
||||
49
Task/Long-year/S-BASIC/long-year.basic
Normal file
49
Task/Long-year/S-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
$lines
|
||||
|
||||
rem - compute p mod q
|
||||
function mod(p, q = integer) = integer
|
||||
end = p - q * (p/q)
|
||||
|
||||
comment
|
||||
return day of week (Sun = 0, Mon = 1, etc.) for a
|
||||
given Gregorian calendar date using Zeller's congruence
|
||||
end
|
||||
function dayofweek (mo, da, yr = integer) = integer
|
||||
var y, c, z = integer
|
||||
if mo < 3 then
|
||||
begin
|
||||
mo = mo + 10
|
||||
yr = yr - 1
|
||||
end
|
||||
else mo = mo - 2
|
||||
y = mod(yr,100)
|
||||
c = int(yr / 100)
|
||||
z = int((26 * mo - 2) / 10)
|
||||
z = z + da + y + int(y/4) + int(c/4) - 2 * c + 777
|
||||
z = mod(z,7)
|
||||
end = z
|
||||
|
||||
comment
|
||||
The simplest of several possible tests is that
|
||||
any calendar year starting or ending on a
|
||||
Thursday is "long", i.e., has 53 ISO weeks
|
||||
end
|
||||
function islongyear(yr = integer) = integer
|
||||
var thursday, result = integer
|
||||
thursday = 4
|
||||
if (dayofweek(1,1,yr) = thursday) or \
|
||||
(dayofweek(12,31,yr) = thursday) then
|
||||
result = -1 rem "true"
|
||||
else
|
||||
result = 0 rem "false"
|
||||
end = result
|
||||
|
||||
rem - main program begins here
|
||||
|
||||
var year = integer
|
||||
print "ISO years that will be long in this century:"
|
||||
for year = 2000 to 2099
|
||||
if islongyear(year) then print year;
|
||||
next year
|
||||
|
||||
end
|
||||
47
Task/Long-year/Scala/long-year.scala
Normal file
47
Task/Long-year/Scala/long-year.scala
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import java.time.temporal.TemporalAdjusters.firstInMonth
|
||||
import java.time.temporal.{ChronoField, IsoFields}
|
||||
import java.time.{DayOfWeek, LocalDate, Month}
|
||||
|
||||
import scala.util.{Failure, Try}
|
||||
|
||||
private object LongYear extends App {
|
||||
private val (currentCentury, maxWeekNumber) = (LocalDate.now().getYear / 100, ChronoField.ALIGNED_WEEK_OF_YEAR.range().getMaximum)
|
||||
private val centuries = currentCentury * 100 until (currentCentury + 1) * 100
|
||||
private val results = List(
|
||||
centuries.filter(isThursdayFirstOrLast),
|
||||
centuries.filter(year => maxIsoWeeks(year) == maxWeekNumber),
|
||||
centuries.filter(mostThursdaysInYear)
|
||||
)
|
||||
|
||||
// Solution 1, the first or respectively last day of the year is a Thursday.
|
||||
private def isThursdayFirstOrLast(_year: Int): Boolean = {
|
||||
|
||||
LocalDate.of(_year, Month.DECEMBER, 31).get(ChronoField.DAY_OF_WEEK) == DayOfWeek.THURSDAY.getValue ||
|
||||
LocalDate.of(_year, Month.JANUARY, 1).get(ChronoField.DAY_OF_WEEK) == DayOfWeek.THURSDAY.getValue
|
||||
}
|
||||
|
||||
// Solution 2, if last week that contains at least four days of the month of December.
|
||||
private def maxIsoWeeks(_year: Int) = {
|
||||
// The last week that contains at least four days of the month of December.
|
||||
LocalDate.of(_year, Month.DECEMBER, 28).get(IsoFields.WEEK_OF_WEEK_BASED_YEAR)
|
||||
}
|
||||
|
||||
// Solution 3, if there are 52 Thursdays in a year
|
||||
private def mostThursdaysInYear(_year: Int) = {
|
||||
val datum = LocalDate.of(_year, Month.JANUARY, 1).`with`(firstInMonth(DayOfWeek.THURSDAY))
|
||||
|
||||
datum.plusDays(52 * 7).getYear == _year
|
||||
}
|
||||
|
||||
println(s"Years in this ${currentCentury + 1}st century having ISO week $maxWeekNumber :")
|
||||
|
||||
Try { // Testing the solutions
|
||||
assert(results.tail.forall(_ == results.head), "Discrepancies in results.")
|
||||
} match {
|
||||
case Failure(ex) => Console.err.println(ex.getMessage)
|
||||
case _ =>
|
||||
}
|
||||
|
||||
results.zipWithIndex.foreach(solution => println(s"Solution ${solution._2}: ${solution._1.mkString(" ")}"))
|
||||
|
||||
}
|
||||
7
Task/Long-year/Scheme/long-year.ss
Normal file
7
Task/Long-year/Scheme/long-year.ss
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(define (dec31wd year)
|
||||
(remainder (apply + (map (lambda (d) (quotient year d)) '(1 4 -100 400))) 7))
|
||||
|
||||
(define (long? year) (or (= 4 (dec31wd year)) (= 3 (dec31wd (- year 1)))))
|
||||
|
||||
(display "Long years between 1800 and 2100:") (newline)
|
||||
(display (filter long? (iota 300 1800)))
|
||||
7
Task/Long-year/Sidef/long-year.sidef
Normal file
7
Task/Long-year/Sidef/long-year.sidef
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
func is_long_year(year) {
|
||||
Date.parse("#{year}-12-28", "%Y-%m-%d").week == 53
|
||||
}
|
||||
|
||||
say ( "Long years in the 20th century:\n", (1900..^2000).grep(is_long_year))
|
||||
say ("\nLong years in the 21st century:\n", (2000..^2100).grep(is_long_year))
|
||||
say ("\nLong years in the 22nd century:\n", (2100..^2200).grep(is_long_year))
|
||||
19
Task/Long-year/Snobol/long-year.sno
Normal file
19
Task/Long-year/Snobol/long-year.sno
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
DEFINE('DEC31WD(Year)') :(END_DEC31WD)
|
||||
DEC31WD DEC31WD = REMDR(Year + (Year / 4) - (Year / 100) + (Year / 400), 7) :(RETURN)
|
||||
END_DEC31WD
|
||||
|
||||
DEFINE('ISOLONG(Year)') :(END_ISOLONG)
|
||||
ISOLONG EQ(DEC31WD(Year), 4) :S(RETURN)
|
||||
EQ(DEC31WD(Year - 1), 3) :S(RETURN)F(FRETURN)
|
||||
END_ISOLONG
|
||||
|
||||
DEFINE('ISODEMO(Start,End)') :(END_ISODEMO)
|
||||
ISODEMO OUTPUT = 'ISO long years between ' Start ' and ' End ':'
|
||||
Year = Start
|
||||
LOOP OUTPUT = ISOLONG(Year) Year
|
||||
Year = Year + 1
|
||||
LE(YEAR, 2045) :S(LOOP) F(RETURN)
|
||||
END_ISODEMO
|
||||
|
||||
ISODEMO(1995, 2045)
|
||||
END
|
||||
11
Task/Long-year/Swift/long-year.swift
Normal file
11
Task/Long-year/Swift/long-year.swift
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
func isLongYear(_ year: Int) -> Bool {
|
||||
let year1 = year - 1
|
||||
let p = (year + (year / 4) - (year / 100) + (year / 400)) % 7
|
||||
let p1 = (year1 + (year1 / 4) - (year1 / 100) + (year1 / 400)) % 7
|
||||
|
||||
return p == 4 || p1 == 3
|
||||
}
|
||||
|
||||
for range in [1900...1999, 2000...2099, 2100...2199] {
|
||||
print("\(range): \(range.filter(isLongYear))")
|
||||
}
|
||||
25
Task/Long-year/Tcl/long-year.tcl
Normal file
25
Task/Long-year/Tcl/long-year.tcl
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
## Reference: https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
|
||||
|
||||
proc p {year} {
|
||||
return [expr {($year + ($year/4) - ($year/100) + ($year/400)) % 7}]
|
||||
}
|
||||
|
||||
proc is_long_year {year} {
|
||||
return [expr {[p $year] == 4 || [p [expr {$year - 1}]] == 3}]
|
||||
}
|
||||
|
||||
proc print_long_years {from to} {
|
||||
for {set year $from; set count 0} {$year <= $to} {incr year} {
|
||||
if {[is_long_year $year]} {
|
||||
if {$count > 0} {
|
||||
puts -nonewline [expr {($count % 10 == 0) ? "\n" : " "}]
|
||||
}
|
||||
puts -nonewline $year
|
||||
incr count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
puts "Long years between 1800 and 2100:"
|
||||
print_long_years 1800 2100
|
||||
puts ""
|
||||
9
Task/Long-year/Terraform/long-year-1.terraform
Normal file
9
Task/Long-year/Terraform/long-year-1.terraform
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
module "iso-long-years" {
|
||||
source = "./iso-long-years"
|
||||
start_year = 1995
|
||||
end_year = 2045
|
||||
}
|
||||
|
||||
output "long-years" {
|
||||
value = module.iso-long-years.long-years
|
||||
}
|
||||
22
Task/Long-year/Terraform/long-year-2.terraform
Normal file
22
Task/Long-year/Terraform/long-year-2.terraform
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
variable start_year {
|
||||
type = number
|
||||
}
|
||||
|
||||
variable end_year {
|
||||
type = number
|
||||
}
|
||||
|
||||
locals {
|
||||
year_list = range(var.start_year, var.end_year+1)
|
||||
}
|
||||
|
||||
module "iso-long-year" {
|
||||
for_each = toset([for y in local.year_list: tostring(y)])
|
||||
source = "../iso-long-year"
|
||||
year = each.key
|
||||
}
|
||||
|
||||
output "long-years" {
|
||||
value = compact([for y in [for n in local.year_list: tostring(n)]:
|
||||
module.iso-long-year[y].isLong ? y : ""])
|
||||
}
|
||||
16
Task/Long-year/Terraform/long-year-3.terraform
Normal file
16
Task/Long-year/Terraform/long-year-3.terraform
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
variable year {
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
locals {
|
||||
ystr = var.year != "" ? var.year : split("-",timestamp())[0]
|
||||
y = tonumber(local.ystr)
|
||||
e = local.y - 1
|
||||
dec31 = local.y * 365 + floor(local.y/4) - floor(local.y/100) + floor(local.y/400)
|
||||
jan1 = local.e * 365 + floor(local.e/4) - floor(local.e/100) + floor(local.e/400) + 1
|
||||
}
|
||||
|
||||
output isLong {
|
||||
value = (local.dec31 % 7 == 4 || local.jan1 % 7 == 4)
|
||||
}
|
||||
15
Task/Long-year/Tiny-BASIC/long-year.basic
Normal file
15
Task/Long-year/Tiny-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
PRINT "What year would you like?"
|
||||
INPUT Y
|
||||
LET X = Y
|
||||
GOSUB 100
|
||||
IF P = 4 THEN LET L = 1
|
||||
LET X = Y - 1
|
||||
GOSUB 100
|
||||
IF P = 3 THEN LET L = 1
|
||||
IF L = 1 THEN PRINT Y," is a long year."
|
||||
IF L = 0 THEN PRINT Y," is not a long year."
|
||||
END
|
||||
100 LET P = X + X/4 - X/100 + X/400
|
||||
110 IF P < 7 THEN RETURN
|
||||
LET P = P - 7
|
||||
GOTO 110
|
||||
16
Task/Long-year/True-BASIC/long-year.basic
Normal file
16
Task/Long-year/True-BASIC/long-year.basic
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
FUNCTION p(y) = REMAINDER((y + INT(y/4) - INT(y/100) + INT(y/400)), 7)
|
||||
|
||||
FUNCTION isLongYear(y)
|
||||
IF p(y) = 4 THEN
|
||||
LET isLongYear = 1
|
||||
ELSEIF p(y-1) = 3 THEN
|
||||
LET isLongYear = 1
|
||||
ELSE
|
||||
LET isLongYear = 0
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
FOR y = 2000 TO 2100
|
||||
IF isLongYear(y) > 0 THEN PRINT y
|
||||
NEXT y
|
||||
END
|
||||
11
Task/Long-year/TypeScript/long-year.ts
Normal file
11
Task/Long-year/TypeScript/long-year.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
const isLongYear = (year: number): boolean => {
|
||||
const jan1: Date = new Date(year, 0, 1);
|
||||
const dec31: Date = new Date(year, 11, 31);
|
||||
return (4 == jan1.getDay() || 4 == dec31.getDay())
|
||||
}
|
||||
|
||||
for (let y: number = 1995; y <= 2045; y++) {
|
||||
if (isLongYear(y)) {
|
||||
console.log(y)
|
||||
}
|
||||
}
|
||||
4
Task/Long-year/UNIX-Shell/long-year-1.sh
Normal file
4
Task/Long-year/UNIX-Shell/long-year-1.sh
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
long_year() {
|
||||
cal 1 $1 | grep -q ' 3 *$' && return 0
|
||||
cal 12 $1 | grep -q ' 26 *$'
|
||||
}
|
||||
3
Task/Long-year/UNIX-Shell/long-year-2.sh
Normal file
3
Task/Long-year/UNIX-Shell/long-year-2.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
long_year() {
|
||||
expr $(date -d "$1-12-28" +%V) = 53 >/dev/null
|
||||
}
|
||||
12
Task/Long-year/UNIX-Shell/long-year-3.sh
Normal file
12
Task/Long-year/UNIX-Shell/long-year-3.sh
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
dec31wd() {
|
||||
# return weekday (time_t tm_wday, 0=Sunday) of December 31st of the given year
|
||||
typeset -i y=$1
|
||||
echo $(( (y + y / 4 - y / 100 + y / 400) % 7 ))
|
||||
}
|
||||
|
||||
# the year is long if the year starts or ends on a Thursday (starts on a
|
||||
# Thursday = the previous year ends on a Wednesday)
|
||||
long_year() {
|
||||
typeset -i y=$1
|
||||
(( 4 == $(dec31wd $y) || 3 == $(dec31wd $(( y - 1 ))) ))
|
||||
}
|
||||
5
Task/Long-year/UNIX-Shell/long-year-4.sh
Normal file
5
Task/Long-year/UNIX-Shell/long-year-4.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
for y in $(seq 1995 2045); do
|
||||
if long_year $y; then
|
||||
echo $y
|
||||
fi
|
||||
done | column
|
||||
22
Task/Long-year/Visual-Basic/long-year.vb
Normal file
22
Task/Long-year/Visual-Basic/long-year.vb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Option Explicit
|
||||
|
||||
Function IsLongYear(ByVal Year As Integer) As Boolean
|
||||
Select Case vbThursday
|
||||
Case VBA.DatePart("w", VBA.DateSerial(Year, 1, 1)), _
|
||||
VBA.DatePart("w", VBA.DateSerial(Year, 12, 31))
|
||||
IsLongYear = True
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Sub Main()
|
||||
'test
|
||||
Dim l As Long
|
||||
For l = 1990 To 2021
|
||||
Select Case l
|
||||
Case 1992, 1998, 2004, 2009, 2015, 2020
|
||||
Debug.Assert IsLongYear(l)
|
||||
Case Else
|
||||
Debug.Assert Not IsLongYear(l)
|
||||
End Select
|
||||
Next l
|
||||
End Sub
|
||||
15
Task/Long-year/Wren/long-year.wren
Normal file
15
Task/Long-year/Wren/long-year.wren
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import "/date" for Date
|
||||
|
||||
var centuries = ["20th", "21st", "22nd"]
|
||||
var starts = [1900, 2000, 2100]
|
||||
for (i in 0...centuries.count) {
|
||||
var longYears = []
|
||||
System.print("\nLong years in the %(centuries[i]) century:")
|
||||
for (j in starts[i]...starts[i]+100) {
|
||||
var t = Date.new(j, 12, 28)
|
||||
if (t.weekOfYear[1] == 53) {
|
||||
longYears.add(j)
|
||||
}
|
||||
}
|
||||
System.print(longYears)
|
||||
}
|
||||
21
Task/Long-year/XBasic/long-year.basic
Normal file
21
Task/Long-year/XBasic/long-year.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
PROGRAM "LongYear"
|
||||
VERSION "0.0000"
|
||||
|
||||
DECLARE FUNCTION Entry ()
|
||||
DECLARE FUNCTION p (y)
|
||||
DECLARE FUNCTION isLongYear (y)
|
||||
|
||||
FUNCTION Entry ()
|
||||
FOR y = 2000 TO 2100
|
||||
IF isLongYear(y) THEN PRINT y,
|
||||
NEXT y
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION p (y)
|
||||
RETURN (y + INT(y/4) - INT(y/100) + INT(y/400)) MOD 7
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION isLongYear (y)
|
||||
RETURN (p(y) = 4) OR (p(y - 1) = 3)
|
||||
END FUNCTION
|
||||
END PROGRAM
|
||||
24
Task/Long-year/XPL0/long-year.xpl0
Normal file
24
Task/Long-year/XPL0/long-year.xpl0
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
\Long year
|
||||
code Rem=2, CrLf=9, IntIn=10, IntOut=11, Text=12, Clear=40;
|
||||
integer S, E, Y;
|
||||
|
||||
function integer Weekday(Y);
|
||||
\Weekday of Y-12-31, 0 Sunday
|
||||
integer Y;
|
||||
return Rem((Y + Y / 4 - Y / 100 + Y / 400) / 7);
|
||||
|
||||
function integer IsLongYear(Y);
|
||||
integer Y;
|
||||
return 4 = Weekday(Y) ! 3 = Weekday(Y - 1);
|
||||
|
||||
begin
|
||||
Clear;
|
||||
Text(0, "**** List of ISO long years ****");
|
||||
CrLf(0);
|
||||
Text(0, "Start year: "); S:= IntIn(0);
|
||||
Text(0, "End year: "); E:= IntIn(0);
|
||||
CrLf(0);
|
||||
for Y:= S, E do
|
||||
if IsLongYear(Y) then [IntOut(0, Y); Text(0, " ")];
|
||||
CrLf(0);
|
||||
end
|
||||
12
Task/Long-year/Yabasic/long-year.basic
Normal file
12
Task/Long-year/Yabasic/long-year.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
sub p(y)
|
||||
return mod((y + int(y/4) - int(y/100) + int(y/400)), 7)
|
||||
end sub
|
||||
|
||||
sub isLongYear(y)
|
||||
return (p(y) = 4) or (p(y - 1) = 3)
|
||||
end sub
|
||||
|
||||
for y = 2000 to 2100
|
||||
if isLongYear(y) print y
|
||||
next y
|
||||
end
|
||||
5
Task/Long-year/Zkl/long-year.zkl
Normal file
5
Task/Long-year/Zkl/long-year.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
fcn isLongYear(y){ Time.Date.weeksInYear(y)==53 }
|
||||
foreach nm,y in (T(T("20th",1900), T("21st",2000), T("22nd",2100))){
|
||||
println("\nLong years in the %s century:\n%s".fmt(nm,
|
||||
[y..y+99].filter(isLongYear).concat(" ")));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue