Day of the week of Christmas and New Year: Difference between revisions

m
Line 621:
func dayOfTheWeek year month day .
# Based on Conway's doomsday algorithm
# 1. Calculate the doomsday for the century
century = floor (year / 100)
if century mod 4 = 0
Line 632 ⟶ 631:
centuryDoomsday = 3
.
# 2. Find the doomsday of the year
mainYear = year mod 100
yearDoomsday = (floor (mainYear / 12) + mainYear mod 12 + floor (mainYear mod 12 / 4) + centuryDoomsday) mod 7
# 3. Check if the year is leap
if mainYear = 0
if century mod 4 = 0
Line 649 ⟶ 646:
.
.
# 4. Calculate the DOTW of January 1
if leap = 1
januaryOne = (yearDoomsday + 4) mod 7
Line 655 ⟶ 651:
januaryOne = (yearDoomsday + 5) mod 7
.
monthDays[] = [ 0 31 59 90 120 151 181 212 243 273 304 334 ]
# 5. Determine the nth day of the year
nthDay = monthDays[month]
if month = 1
if month > NthDay = 02
elif month nthDay += 2leap
NthDay = 31
elif month = 3
NthDay = 59 + leap
elif month = 4
NthDay = 90 + leap
elif month = 5
NthDay = 120 + leap
elif month = 6
NthDay = 151 + leap
elif month = 7
NthDay = 181 + leap
elif month = 8
NthDay = 212 + leap
elif month = 9
NthDay = 243 + leap
elif month = 10
NthDay = 273 + leap
elif month = 11
NthDay = 304 + leap
elif month = 12
NthDay = 334 + leap
.
NthDaynthDay += day
return (januaryOne + NthDaynthDay - 1) mod 7 + 1
# 6. Finally, calculate the day of the week
return (januaryOne + NthDay - 1) mod 7
.
days$[] = [ "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" ]
func$ numberToDay n .
#
if n = 0
print "2021-12-25 is on " & numberToDay (days$[dayOfTheWeek 2021 12 25)]
day$ = "Sunday"
print "2022-1-1 is on " & numberToDay (days$[dayOfTheWeek 2022 1 1)</syntaxhighlight>]
elif n = 1
</syntaxhighlight>
day$ = "Monday"
elif n = 2
day$ = "Tuesday"
elif n = 3
day$ = "Wednesday"
elif n = 4
day$ = "Thursday"
elif n = 5
day$ = "Friday"
elif n = 6
day$ = "Saturday"
.
return day$
.
print "2021-12-25 is on " & numberToDay (dayOfTheWeek 2021 12 25)
print "2022-1-1 is on " & numberToDay (dayOfTheWeek 2022 1 1)</syntaxhighlight>
{{out}}
<pre>
1,995

edits