RosettaCodeData/Task/Long-year/S-BASIC/long-year.basic

50 lines
1.1 KiB
Plaintext

$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 ISO year starting or ending on a
Thursday is "long", i.e., spans 53 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