50 lines
1.2 KiB
Text
50 lines
1.2 KiB
Text
type Date = struct {
|
|
word year;
|
|
byte month;
|
|
byte day;
|
|
};
|
|
|
|
proc leap_year(word y) bool:
|
|
y%4 = 0 and (y%100 /= 0 or y % 400 = 0)
|
|
corp
|
|
|
|
proc weekday(Date date) *char:
|
|
[12]byte leapdoom = (4,1,7,4,2,6,4,1,5,3,7,5);
|
|
[12]byte normdoom = (3,7,7,4,2,6,4,1,5,3,7,5);
|
|
word c, r, s, t, c_anchor, doom, anchor;
|
|
|
|
c := date.year / 100;
|
|
r := date.year % 100;
|
|
s := r / 12;
|
|
t := r % 12;
|
|
|
|
c_anchor := (5 * (c % 4) + 2) % 7;
|
|
doom := (s + t + (t/4) + c_anchor) % 7;
|
|
anchor := if leap_year(date.year)
|
|
then leapdoom[date.month-1]
|
|
else normdoom[date.month-1]
|
|
fi;
|
|
|
|
case (doom+date.day-anchor+7)%7
|
|
incase 0: "Sunday"
|
|
incase 1: "Monday"
|
|
incase 2: "Tuesday"
|
|
incase 3: "Wednesday"
|
|
incase 4: "Thursday"
|
|
incase 5: "Friday"
|
|
incase 6: "Saturday"
|
|
esac
|
|
corp
|
|
|
|
proc main() void:
|
|
[7]Date dates = (
|
|
(1800,1,6), (1875,3,29), (1915,12,7), (1970,12,23), (2043,5,14),
|
|
(2077,2,12), (2101,4,2)
|
|
);
|
|
|
|
word d;
|
|
for d from 0 upto 6 do
|
|
writeln(dates[d].month:2, '/', dates[d].day:2, '/', dates[d].year:4,
|
|
": ", weekday(dates[d]))
|
|
od
|
|
corp
|