RosettaCodeData/Task/Doomsday-rule/Yabasic/doomsday-rule.basic

45 lines
1.1 KiB
Plaintext

dim fdoom(1, 12)
for x = 0 to arraysize(fdoom(),1)
for y = 1 to arraysize(fdoom(),2)
read fdoom(x, y)
next y
next x
dim days$(6)
for x = 0 to arraysize(days$(),1)
read days$(x)
next x
sub doomsday(y)
// John Conway's doomsday formula
return mod((2 + 5*mod(y, 4) + 4*mod(y, 100) + 6*mod(y, 400)), 7)
end sub
sub leap(y)
//is it a leap year?
//return 0 for common years, 1 for leap years
if mod(y, 4) > 0 then return 0 : fi
if mod(y, 100) = 0 and mod(y, 400) > 0 then return 0 : fi
return 1
end sub
sub get_day$(d, m, y)
c = doomsday(y)
diff = mod((7 + d - fdoom(leap(y), m)), 7)
return days$(mod((c+diff), 7))
end sub
print get_day$(06, 01, 1800)
print get_day$(29, 03, 1875)
print get_day$(07, 12, 1915)
print get_day$(23, 12, 1970)
print get_day$(14, 05, 2043)
print get_day$(12, 02, 2077)
print get_day$(02, 04, 2101)
end
//the first doomsday in each month for common and leap years
data 3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5
data 4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5
data "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"