Long year: Difference between revisions

Added Easylang
(Long year in Chipmunk Basic)
(Added Easylang)
 
(12 intermediate revisions by 8 users not shown)
Line 240:
<pre>
long years 2000-2099: 2004 2009 2015 2020 2026 2032 2037 2043 2048 2054 2060 2065 2071 2076 2082 2088 2093 2099
</pre>
 
=={{header|Amazing Hopper}}==
Task solves with Amazing Hopper flavour Basico:
<syntaxhighlight lang="c">
 
#include <basico.h>
 
#proto esañolargo(_X_)
 
algoritmo
 
año=1800, c=5
imprimir ("Long (53 week) years between 1800 and 2100:\n\n" )
iterar grupo ( ++año, #( año<=2100 ), \
cuando ( #( es año largo( año )==4 || es año largo( año-1 )==3 ) ){ \
imprimir ( año, " ", solo si( #( c==0 ) , NL; c=6 ), --c ) } )
terminar
 
subrutinas
 
es año largo (y)
retornar ' #( (y + floor(y / 4) - floor(y / 100) + floor(y / 400)) % 7 ) '
</syntaxhighlight>
{{out}}
<pre>
Long (53 week) years between 1800 and 2100:
 
1801 1807 1812 1818 1824 1829
1835 1840 1846 1852 1857 1863
1868 1874 1880 1885 1891 1896
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>
 
Line 509 ⟶ 549:
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
Line 572 ⟶ 612:
false
</pre>
 
==={{header|Gambas}}===
{{trans|BASIC256}}
<syntaxhighlight lang="vbnet">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</syntaxhighlight>
{{out}}
<pre>Same as BASIC256 entry.</pre>
 
==={{header|GW-BASIC}}===
Line 597 ⟶ 663:
170 NEXT
180 PRINT</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{trans| Commodore BASIC}}
<syntaxhighlight lang="qbasic">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</syntaxhighlight>
{{out}}
<pre>Similar as Commodore BASIC entry.</pre>
 
==={{header|Nascom BASIC}}===
Line 630 ⟶ 715:
 
1998 2004 2009 2015 2020 2026 2032 2037 2043
</pre>
 
==={{header|Palo Alto Tiny BASIC}}===
{{trans|Commodore BASIC}}
<syntaxhighlight lang="basic">
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
</syntaxhighlight>
{{out}}
<pre>
*** LIST OF ISO LONG YEARS ***
START YEAR:1995
END YEAR:2045
1998 2004 2009 2015 2020 2026 2032 2037 2043
</pre>
 
Line 653 ⟶ 774:
EndIf</syntaxhighlight>
{{out}}
<pre>Same as BASIC256 entry.</pre>
<pre>
Igual que la entrada de BASIC256.
</pre>
 
==={{header|Quick BASICQuickBASIC}}===
{{Works with|QB|4.x}}
{{Works with|PDS|7.x}}
Line 708 ⟶ 827:
</pre>
 
==={{header|S-BasicRun BASIC}}===
{{trans|BASIC256}}
<syntaxhighlight lang="vb">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</syntaxhighlight>
{{out}}
<pre>Same as BASIC256 entry.</pre>
 
==={{header|S-BASIC}}===
<syntaxhighlight lang="basic">
$lines
Line 737 ⟶ 873:
comment
The simplest of several possible tests is that
any calendarISO year starting or ending on a
Thursday is "long", i.e., hasspans 53 ISO weeks
end
function islongyear(yr = integer) = integer
Line 813 ⟶ 949:
END</syntaxhighlight>
{{out}}
<pre>Same as BASIC256 entry.</pre>
<pre>
 
Igual que la entrada de BASIC256.
==={{header|Visual Basic}}===
</pre>
{{works with|Visual Basic|5}}
{{works with|Visual Basic|6}}
{{works with|VBA|Access 97}}
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<syntaxhighlight lang="vb">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
</syntaxhighlight>
 
===={{header|Visual Basic for DOS}}====
{{trans|Delphi}}
<syntaxhighlight lang="vb">OPTION EXPLICIT
 
DECLARE FUNCTION p (Yr AS INTEGER) AS INTEGER
DECLARE FUNCTION LongYear (Yr AS INTEGER) AS INTEGER
 
DIM iYi AS INTEGER, iYf AS INTEGER, i AS INTEGER
 
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 p (Yr AS INTEGER) AS INTEGER
p = (Yr + INT(Yr / 4) - INT(Yr / 100) + INT(Yr / 400)) MOD 7
END FUNCTION
 
FUNCTION LongYear (Yr AS INTEGER) AS INTEGER
LongYear = (p(Yr) = 4) OR (p(Yr - 1) = 3)
END FUNCTION
</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
{{trans|BASIC256}}
<syntaxhighlight lang="qbasic">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</syntaxhighlight>
{{out}}
<pre>Same as BASIC256 entry.</pre>
 
==={{header|Yabasic}}===
Line 828 ⟶ 1,054:
 
for y = 2000 to 2100
if isLongYear(y) then print y : fi
next y
end</syntaxhighlight>
{{out}}
<pre>Same as BASIC256 entry.</pre>
<pre>
Igual que la entrada de BASIC256.
</pre>
 
=={{header|BCPL}}==
Line 1,044 ⟶ 1,268:
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|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub longyear(year: uint16): (r: uint8) is
sub p(y: uint16): (d: uint8) is
d := ((y + y/4 - y/100 + y/400) % 7) as uint8;
end sub;
 
r := 0;
if p(year) == 4 or p(year-1) == 3 then
r := 1;
end if;
end sub;
 
var year: uint16 := 2000;
while year <= 2100 loop
if longyear(year) != 0 then
print_i16(year);
print_nl();
end if;
year := year + 1;
end loop;</syntaxhighlight>
{{out}}
<pre>2004
2009
2015
2020
2026
2032
2037
2043
2048
2054
2060
2065
2071
2076
2082
2088
2093
2099</pre>
 
=={{header|Dc}}==
Line 1,162 ⟶ 1,428:
end.
</syntaxhighlight>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc p(word y) word:
(y + y/4 - y/100 + y/400) % 7
corp
 
proc longyear(word y) bool:
p(y) = 4 or p(y-1) = 3
corp
 
proc main() void:
word y;
for y from 2000 upto 2100 do
if longyear(y) then writeln(y) fi
od
corp</syntaxhighlight>
{{out}}
<pre>2004
2009
2015
2020
2026
2032
2037
2043
2048
2054
2060
2065
2071
2076
2082
2088
2093
2099</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func p y .
return (y + y div 4 - y div 100 + y div 400) mod 7
.
func longyear y .
return if p y = 4 or p (y - 1) = 3
.
for y = 2000 to 2100
if longyear y = 1
write y & " "
.
.
</syntaxhighlight>
 
{{out}}
<pre>
2004 2009 2015 2020 2026 2032 2037 2043 2048 2054 2060 2065 2071 2076 2082 2088 2093 2099
</pre>
 
=={{header|Elixir}}==
Line 1,569 ⟶ 1,890:
2037
2043</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">function isLongYear (y)
local function p (y)
local f = math.floor
return (y + f(y/4) - f(y/100) + f(y/400)) % 7
end
return p(y) == 4 or p(y - 1) == 3
end
 
print("Long years in the 21st century:")
for year = 2001, 2100 do
if isLongYear(year) then io.write(year .. " ") end
end</syntaxhighlight>
{{out}}
<pre>Long years in the 21st century:
2004 2009 2015 2020 2026 2032 2037 2043 2048 2054 2060 2065 2071 2076 2082 2088 2093 2099</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">firstyear = 2000;
Line 2,144 ⟶ 2,483:
 
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program determines ifIf a (calendar) year is a SHORTshort or LONGlong year (52 or 53 weeks).*/
parse/* arg LO HI . /*obtain optional args. (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.*/
current=left(date('S'),4)
if HI=='' | HI=="," then HI= LO /* " " " " */
If lo=='' | lo=="," | lo=='*' Then lo=current /*Not given? Use default.*/
if HI=='*' then HI= left( date('S'), 4) /*an asterisk ≡ current yr*/
If hi=='' | hi=="," Then hi=lo /* " " " " */
If hi=='*' Then hi=current /*an asterisk: current yr*/
 
Do do jyr=LO to HI lo To hi /* process single yr or range of years.*/
saySay ' year ' yr j "' is a " right( word('short long', weeks(j)-51),5) " year"
right(word('short long',is_long(yr)+1),5) ' year'
end /*j*/
End
exit 0 /*stick a fork in it, we're all done. */
Exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*----------------------------------------------------------------------*/
pWeek: parse arg #; return (# + # % 4 - # % 100 + # % 400) // 7
wd_1231:
weeks: parse arg y; if pWeek(y)==4 | pWeek(y-1)==3 then return 53; return 52</syntaxhighlight>
/*************************************************************************
* returns the day of the week of 31 December year
*************************************************************************/
Parse Arg year
Return (year+year%4-year%100+year%400)//7
 
is_long:
Parse Arg year
Return wd_1231(year)==4 |, /* year ends in a Thursday */
wd_1231(year-1)==3 /* or previous year ends in a Wednesday */</syntaxhighlight>
{{out|output|text=&nbsp; when using the inputs of: &nbsp; &nbsp; <tt> 1990 &nbsp; 2030 </tt>}}
 
Line 2,640 ⟶ 2,991:
{{Out}}
<pre>1998 2004 2009 2015 2020 2026 2032 2037 2043</pre>
 
=={{header|Visual Basic}}==
{{works with|Visual Basic|5}}
{{works with|Visual Basic|6}}
{{works with|VBA|Access 97}}
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<syntaxhighlight lang="vb">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
</syntaxhighlight>
 
==={{header|Visual Basic for DOS}}===
Translated from Delohi
<syntaxhighlight lang="vb">OPTION EXPLICIT
 
DECLARE FUNCTION p (Yr AS INTEGER) AS INTEGER
DECLARE FUNCTION LongYear (Yr AS INTEGER) AS INTEGER
 
DIM iYi AS INTEGER, iYf AS INTEGER, i AS INTEGER
 
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 p (Yr AS INTEGER) AS INTEGER
p = (Yr + INT(Yr / 4) - INT(Yr / 100) + INT(Yr / 400)) MOD 7
END FUNCTION
 
FUNCTION LongYear (Yr AS INTEGER) AS INTEGER
LongYear = (p(Yr) = 4) OR (p(Yr - 1) = 3)
END FUNCTION
</syntaxhighlight>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-date}}
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
 
var centuries = ["20th", "21st", "22nd"]
2,054

edits