Long year: Difference between revisions

Added Easylang
(Add Draco)
(Added Easylang)
 
(6 intermediate revisions by 6 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 804 ⟶ 844:
<pre>Same as BASIC256 entry.</pre>
 
==={{header|S-BasicBASIC}}===
<syntaxhighlight lang="basic">
$lines
Line 833 ⟶ 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 1,228 ⟶ 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,381 ⟶ 1,463:
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,788 ⟶ 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,363 ⟶ 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 yr=lo To hi /* process single yr or range of */
Say ' year ' yr ' is a ',
right(word('short long',is_long(yr)+1),5) ' year'
End
Exit
/*----------------------------------------------------------------------*/
wd_1231:
/*************************************************************************
* returns the day of the week of 31 December year
*************************************************************************/
Parse Arg year
Return (year+year%4-year%100+year%400)//7
 
is_long:
do j=LO to HI /*process single yr or range of years.*/
Parse Arg year
say ' year ' j " is a " right( word('short long', weeks(j)-51),5) " year"
Return wd_1231(year)==4 |, /* year ends in a Thursday */
end /*j*/
wd_1231(year-1)==3 /* or previous year ends in a Wednesday */</syntaxhighlight>
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</syntaxhighlight>
{{out|output|text=&nbsp; when using the inputs of: &nbsp; &nbsp; <tt> 1990 &nbsp; 2030 </tt>}}
 
Line 2,863 ⟶ 2,995:
{{trans|Go}}
{{libheader|Wren-date}}
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
 
var centuries = ["20th", "21st", "22nd"]
2,054

edits