Day of the week: Difference between revisions

Added MiniScript
(Add CLU)
(Added MiniScript)
 
(42 intermediate revisions by 21 users not shown)
Line 15:
 
=={{header|11l}}==
<langsyntaxhighlight lang="11l">print((2008..2121).filter(y -> Time(y, 12, 25).strftime(‘%w’) == ‘0’))</langsyntaxhighlight>
{{out}}
<pre>
Line 24:
{{trans|REXX}}
The program uses two ASSIST macro (XDECO,XPRNT) to keep the code as short as possible.
<langsyntaxhighlight lang="360asm">* Day of the week 06/07/2016
DOW CSECT
USING DOW,R15 base register
Line 66:
PG DS CL12 buffer
YREGS
END DOW</langsyntaxhighlight>
{{out}}
<pre style="height:16ex"> 2011
Line 87:
 
=={{header|ABAP}}==
<langsyntaxhighlight ABAPlang="abap">report zday_of_week
data: lv_start type i value 2007,
lv_n type i value 114,
Line 111:
endif.
enddo.
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 136:
=={{header|Action!}}==
Action! does not have a standard library providing a day of week function, therefore an adaptation of [https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto.27s_methods Sakamoto's method] to determine the day of week for a given date using integer arithmetic is used.
<syntaxhighlight lang="action!">
<lang Action!>
Byte FUNC DayOfWeek(BYTE day, month CARD year BYTE century)
CARD weekday
Line 166:
OD
RETURN
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 190:
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
Line 200:
end if;
end loop;
end Yuletide;</langsyntaxhighlight>
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 228:
 
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
<langsyntaxhighlight lang="algol68"># example from: http://www.xs4all.nl/~jmvdveer/algol.html - GPL #
INT sun=0 # , mon=1, tue=2, wed=3, thu=4, fri=5, sat=6 #;
 
Line 250:
new line(stand out)
)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 258:
=={{header|ALGOL W}}==
{{Trans|Fortran}}
<langsyntaxhighlight lang="algolw">begin % find years where Christmas day falls on a Sunday %
integer procedure Day_of_week ( integer value d, m, y );
begin
Line 278:
if day = 1 then writeon( I_W := 5, S_W := 0, year );
end for_year
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 285:
 
=={{header|ALGOL-M}}==
<langsyntaxhighlight lang="algol">
BEGIN
 
Line 326:
 
END
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 349:
</pre>
=={{header|APL}}==
<langsyntaxhighlight lang="apl">⍝ Based on the simplified calculation of Zeller's congruence, since Christmas is after March 1st, no adjustment is required.
⎕IO ← 0 ⍝ Indices are 0-based
y ← 2008 + ⍳114 ⍝ Years from 2008 to 2121
Line 356:
zeller ← { 7 | +/ (((1↑⍴⍵),6)⍴1 1 1 1 ¯1 1) × ⌊(((⍴⍵)⍴1 13 1)×⍵+(⍴⍵)⍴0 1 0)[;0 1 2 2 2 2]÷((1↑⍴⍵),6)⍴1 5 1 4 100 400 }
result ← (1 = zeller 25,[1]12,[0.5]y) / y
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 364:
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">set ChristmasSundays to {}
set Christmas to (current date)
set month of Christmas to December
Line 372:
if weekday of Christmas is Sunday then set end of ChristmasSundays to |year|
end repeat
ChristmasSundays</langsyntaxhighlight>
 
 
Or, composing generic functions:
<langsyntaxhighlight lang="applescript">
-- xmasIsSunday :: Int -> Bool
on xmasIsSunday(y)
Line 434:
end script
end if
end mReturn</langsyntaxhighlight>
{{Out}}
<langsyntaxhighlight AppleScriptlang="applescript">{2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067,
2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118}</langsyntaxhighlight>
 
=={{header|Arc}}==
<langsyntaxhighlight lang="arc">
(= day-names '(Sunday Monday Tuesday Wednesday Thursday Friday Saturday))
(= get-weekday-num (fn (year month day)
Line 449:
7)))
(= get-weekday-name (fn (weekday-num) (day-names weekday-num)))
</syntaxhighlight>
</lang>
<b>test:</b>
<langsyntaxhighlight lang="arc">(up i 2008 2121
(when (is 0 (get-weekday-num i 12 25))
(prn i)))
Line 473:
2118
 
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]</langsyntaxhighlight>
 
{{out}}
Line 486:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">year = 2008
stop = 2121
 
Line 495:
year++
}
MsgBox,% out</langsyntaxhighlight>
 
=={{header|AutoIt}}==
<langsyntaxhighlight AutoItlang="autoit">#include <date.au3>
Const $iSunday = 1
For $iYear = 2008 To 2121 Step 1
Line 504:
ConsoleWrite(StringFormat($iYear & "\n"))
EndIf
Next</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
 
<lang AWK>
# syntax: GAWK -f DAY_OF_THE_WEEK.AWK
# runtime does not support years > 2037 on my 32-bit Windows XP O/S
Line 517 ⟶ 516:
}
}
</syntaxhighlight>
</lang>
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{trans|Commodore BASIC}}
<syntaxhighlight lang="gwbasic"> 1 DEF FN D7(N) = N - 7 * INT (N / 7)
2 DEF FN RD(Y) = 365 * Y + INT (Y / 4) - INT (Y / 100) + INT (Y / 400)
3 PRINT "YEARS WITH CHRISTMAS ON A SUNDAY" CHR$ (13)
4 FOR Y = 2008 TO 2121
5 IF NOT FN D7( FN RD(Y) - 6) THEN PRINT Y,
6 NEXT Y</syntaxhighlight>
==={{header|ASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="basic">
REM Day of the week
Month = 12
Day = 25
FOR Year = 2007 TO 2122
GOSUB CalcDayOfWeek:
IF DayOfWeek = 0 THEN
PRINT Year;
ENDIF
NEXT Year
PRINT
END
 
CalcDayOfWeek:
<b>Works with:</b> FreeBASIC <br>
REM Sunday = 0, Saturday = 6
This program needs the modulo function because there is a bug in the built in modulo function.
IF Month < 3 THEN
 
Year = Year - 1
<lang BASIC>Declare Function modulo(x As Double, y As Double) As Double
Month = Month + 12
Declare Function wd(m As Double, d As Double, y As Double) As Integer
ENDIF
 
DayOfWeek = Year
Cls
YearDiv = Year / 4
Dim yr As Double
DayOfWeek = DayOfWeek + YearDiv
For yr = 2008 To 2121
YearDiv = Year / 100
If wd(12,25,yr) = 1 Then
DayOfWeek = DayOfWeek - YearDiv
Print "Dec " & 25 & ", " & yr
YearDiv = Year / 400
EndIf
DayOfWeek = DayOfWeek + YearDiv
Next
DayPlus = 153 * Month
Sleep
DayPlus = DayPlus + 8
 
DayPlus = DayPlus / 5
Function modulo(x As Double, y As Double) As Double
DayOfWeek = DayOfWeek + Day
If y = 0 Then
DayOfWeek = DayOfWeek + DayPlus
Return x
DayOfWeek = DayOfWeek MOD 7
Else
RETURN
Return x - y * Int(x / y)
</syntaxhighlight>
End If
{{out}}
End Function
<pre>
 
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
Function wd(m As Double, d As Double, y As Double) As Integer
</pre>
If m = 1 Or m = 2 Then
m += 12
y-= 1
End If
Return modulo(365 * y + Fix(y / 4) - Fix(y / 100) + Fix(y / 400) + d + Fix((153 * m + 8) / 5), 7) + 1
End Function
 
Dec 25, 2011
Dec 25, 2016
Dec 25, 2022
Dec 25, 2033
Dec 25, 2039
Dec 25, 2044
Dec 25, 2050
Dec 25, 2061
Dec 25, 2067
Dec 25, 2072
Dec 25, 2078
Dec 25, 2089
Dec 25, 2095
Dec 25, 2101
Dec 25, 2107
Dec 25, 2112
Dec 25, 2118</lang>
 
==={{header|Atari BASIC}}===
{{trans|Commodore BASIC}}
<langsyntaxhighlight lang="basic">100 REM FIND YEARS WITH SUNDAY CHRISTMAS
110 PRINT CHR$(125);"SUNDAY CHRISTMASES 2008-2121:":PRINT
120 FOR Y=2008 TO 2121
Line 585 ⟶ 583:
210 PRINT
220 NEXT Y
230 IF FOUND THEN PRINT</langsyntaxhighlight>
 
{{Out}}
Line 598 ⟶ 596:
 
==={{header|BaCon}}===
<langsyntaxhighlight lang="freebasic">' Sunday Christmas
PRINT "Years with Christmas on a Sunday"
FOR y = 2008 TO 2121
tv = TIMEVALUE(y, 12, 25, 0, 0, 0)
IF WEEKDAY$(tv) = "Sunday" THEN PRINT y
NEXT</langsyntaxhighlight>
 
{{out}}
Line 625 ⟶ 623:
2112
2118</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">for yr = 2008 to 2121
if wd(12, 25, yr) = 0 then print "Dec 25 "; yr
next
end
 
function wd(m, d, y)
if m < 3 then # if m = 1 or m = 2 then
m += 12
y -= 1
end if
return (y + (y \ 4) - (y \ 100) + (y \ 400) + d + ((153 * m + 8) \ 5)) % 7
end function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|Applesoft BASIC}}
<syntaxhighlight lang="qbasic">10 CLS : REM 10 HOME for Applesoft BASIC
20 DEF fnd7(n) = n - 7 * INT (n / 7)
30 DEF fnrd(y) = 365 * y + INT (y / 4) - INT (y / 100) + INT (y / 400)
40 PRINT "YEARS WITH CHRISTMAS ON A SUNDAY" CHR$(13)
50 FOR y = 2008 TO 2121
60 IF NOT fn d7(fn rd(y)-6) THEN PRINT y,
70 NEXT y</syntaxhighlight>
{{out}}
<pre>YEARS WITH CHRISTMAS ON A SUNDAY
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 </pre>
 
==={{header|Commodore BASIC}}===
This takes advantage of the dynamic scope of arguments to DEF FN functions to nest definitions and ultimately turn the question "Does Christmas fall on a Sunday in year Y?" into a single Boolean function of the year number. It's easy to run afoul of stack limitations in Microsoft BASICs doing this, especially on older versions that just use the processor's 256-byte stack instead of giving BASIC its own, but this program runs fine even on an unexpanded VIC-20.
 
<langsyntaxhighlight lang="basic">100 REM FIND OUT WHAT YEARS HAVE CHRISTMAS ON A SUNDAY
110 REM MODULO FUNCTION (USES CALLER'S N AS DIVIDEND)
120 DEF FNNM(D) = N - D * INT(N/D)
Line 644 ⟶ 682:
230 : IF FNXS(Y) THEN PRINT Y,:REM PRINT YEARS IN COLUMNS
240 NEXT Y
250 PRINT</langsyntaxhighlight>
 
{{Out}}
Line 654 ⟶ 692:
2095 2101 2107 2112
2118</pre>
 
==={{header|FBSL}}===
<syntaxhighlight lang="qbasic">#APPTYPE CONSOLE
 
'In what years between 2008 and 2121 will the 25th of December be a Sunday?
dim date as integer, dayname as string
for dim year = 2008 to 2121
date = year * 10000 + 1225
dayname = dateconv(date,"dddd")
if dayname = "Sunday" then
print "Christmas Day is on a Sunday in ", year
end if
next
PAUSE
</syntaxhighlight>
 
==={{header|FreeBASIC}}===
<langsyntaxhighlight FreeBASIClang="freebasic">' version 17-06-2015
' compile with: fbc -s console
 
Line 679 ⟶ 732:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>Dec 25 2011
Line 698 ⟶ 751:
Dec 25 2112
Dec 25 2118</pre>
<syntaxhighlight lang="basic">Declare Function modulo(x As Double, y As Double) As Double
<lang FreeBASIC>' version 17-06-2015
Declare Function wd(m As Double, d As Double, y As Double) As Integer
 
Cls
Dim yr As Double
For yr = 2008 To 2121
If wd(12,25,yr) = 1 Then
Print "Dec " & 25 & ", " & yr
EndIf
Next
Sleep
 
Function modulo(x As Double, y As Double) As Double
If y = 0 Then
Return x
Else
Return x - y * Int(x / y)
End If
End Function
 
Function wd(m As Double, d As Double, y As Double) As Integer
If m = 1 Or m = 2 Then
m += 12
y-= 1
End If
Return modulo(365 * y + Fix(y / 4) - Fix(y / 100) + Fix(y / 400) + d + Fix((153 * m + 8) / 5), 7) + 1
End Function
</syntaxhighlight>
{{out}}
<pre>
Dec 25, 2011
Dec 25, 2016
Dec 25, 2022
Dec 25, 2033
Dec 25, 2039
Dec 25, 2044
Dec 25, 2050
Dec 25, 2061
Dec 25, 2067
Dec 25, 2072
Dec 25, 2078
Dec 25, 2089
Dec 25, 2095
Dec 25, 2101
Dec 25, 2107
Dec 25, 2112
Dec 25, 2118
</pre>
<syntaxhighlight lang="freebasic">' version 17-06-2015
' Weekday And DateSerial only works with #Include "vbcompat.bi"
' compile with: fbc -s console
Line 714 ⟶ 815:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>25-12-2011
Line 733 ⟶ 834:
25-12-2112
25-12-2118</pre>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">window 1
 
long y
CFDateRef dt
NSInteger day
CFCalendarRef cal
DateComponentsRef comps
 
cal = fn CalendarCurrent
 
comps = fn DateComponentsInit
DateComponentsSetMonth( comps, 12 )
DateComponentsSetDay( comps, 25 )
 
for y = 2008 to 2121
DateComponentsSetYear( comps, y )
dt = fn CalendarDateFromComponents( cal, comps )
day = fn CalendarComponentFromDate( cal, NSCalendarUnitWeekday, dt )
if ( day == 1 )
print y
end if
next
 
HandleEvents</syntaxhighlight>
 
==={{header|Gambas}}===
'''[https://gambas-playground.proko.eu/?gist=b9b4e9a871e96ea6f1db467fa23669fe Click this link to run this code]'''
<syntaxhighlight lang="gambas">Public Sub Main()
Dim siCount As Short
 
For siCount = 2008 To 2121
If WeekDay(Date(siCount, 12, 25)) = 0 Then Print Format(Date(siCount, 12, 25), "dddd dd mmmm yyyy") & " falls on a Sunday"
Next
 
End</syntaxhighlight>
Output:
<pre>
Sunday 25 December 2011 falls on a Sunday
Sunday 25 December 2016 falls on a Sunday
Sunday 25 December 2022 falls on a Sunday
Sunday 25 December 2033 falls on a Sunday
Sunday 25 December 2039 falls on a Sunday
Sunday 25 December 2044 falls on a Sunday
Sunday 25 December 2050 falls on a Sunday
Sunday 25 December 2061 falls on a Sunday
Sunday 25 December 2067 falls on a Sunday
Sunday 25 December 2072 falls on a Sunday
Sunday 25 December 2078 falls on a Sunday
Sunday 25 December 2089 falls on a Sunday
Sunday 25 December 2095 falls on a Sunday
Sunday 25 December 2101 falls on a Sunday
Sunday 25 December 2107 falls on a Sunday
Sunday 25 December 2112 falls on a Sunday
Sunday 25 December 2118 falls on a Sunday
</pre>
 
==={{header|GW-BASIC}}===
{{works with|BASICA}}
<lang gwbasic>10 M = 12
<syntaxhighlight lang="gwbasic">10 REM Day of the week
20 D = 25
20 DEFINT D, M, Y-Z
30 FOR Y = 2007 TO 2122
30 M = 12: D = 25
40 GOSUB 100
5040 IFFOR ZY = 02007 THENTO PRINT Y2122
50 GOSUB 200
60 NEXT Y
60 IF Z = 0 THEN PRINT Y;
70 END
70 NEXT Y
100 REM CALCULATE DAY OF WEEK Z GIVEN
80 PRINT
110 REM YEAR Y, MONTH M AND DAY D
90 END
120 REM SUNDAY = 0, SATURDAY = 6
170 REM Calculate day of week Z given
130 IF M < 3 THEN Y = Y - 1 : M = M + 12
180 REM year Y, month M, and day D
140 Z = Y + INT(Y/4) - INT(Y/100) + INT(Y/400)
190 REM Sunday = 0, Saturday = 6
150 Z = Z + D + INT((153*M + 8)/5)
200 IF M < 3 THEN Y = Y - 1: M = M + 12
160 Z = Z MOD 7
210 Z = Y + Y \ 4 - Y \ 100 + Y \ 400
170 RETURN</lang>
220 Z = Z + D + (153 * M + 8) \ 5
230 Z = Z MOD 7
240 RETURN</syntaxhighlight>
{{out}}
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "Dayweek.bas"
110 PRINT "The years between 2008 and 2121 will the 25th of December be a Sunday:"
120 FOR Y=2008 TO 2121
Line 761 ⟶ 926:
170 LET W=D+INT((13*(M+12*A-2)-1)/5)+Y+INT(Y/4)-INT(Y/100)+INT(Y/400)
180 LET DAYWEEK=W-7*INT(W/7)
190 END DEF</langsyntaxhighlight>
 
==={{header|Liberty BASIC}}===
{{works with|Just BASIC}}
<syntaxhighlight lang="lb">count = 0
for year = 2008 to 2121
dateString$="12/25/";year
dayNumber=date$(dateString$)
if dayNumber mod 7 = 5 then
count = count + 1
print dateString$
end if
next year
print count; " years when Christmas Day falls on a Sunday"
end</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
{{works with|IS-BASIC}}
<lang gwbasic>
<syntaxhighlight lang="gwbasic">10 REM Find years with Sunday Christmas
20 LET F = 2008
30 LET T = 2121
Line 778 ⟶ 957:
120 NEXT Y
130 PRINT
140 END</syntaxhighlight>
 
</lang>
==={{header|MSX Basic}}===
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
<syntaxhighlight lang="qbasic">10 REM Find years with Sunday Christmas
11 CLS
20 LET F = 2008
30 LET T = 2121
40 PRINT "Sunday Christmases"; F; "-"; T
50 PRINT
60 FOR Y = F TO T
70 LET E = Y * 365 + INT(Y/4) - INT(Y/100) + INT(Y/400)
80 LET X = E - 6
90 LET D = X - 7 * INT(X/7)
100 IF D <> 0 THEN 120
110 PRINT Y; " ";
120 NEXT Y
130 PRINT
140 END</syntaxhighlight>
 
==={{header|Palo Alto Tiny BASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="basic">10 REM DAY OF THE WEEK
20 LET M=12,D=25
30 FOR Y=2007 TO 2122
40 GOSUB 200
50 IF Z=0 PRINT Y," ",
60 NEXT Y
70 PRINT
80 STOP
170 REM CALCULATE DAY OF WEEK Z GIVEN
180 REM YEAR Y, MONTH M, AND DAY D
190 REM SUNDAY = 0, SATURDAY = 6
200 IF M<3 LET Y=Y-1,M=M+12
210 LET Z=Y+Y/4-Y/100+Y/400
220 LET Z=Z+D+(153*M+8)/5
230 LET Z=Z-(Z/7)*7
240 RETURN</syntaxhighlight>
{{out}}
<pre> 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
==={{header|PureBasic}}===
PureBasic's internal Date() is limited between 1970-01-01 00:00:00 and 2038-01-19 03:14:07
<syntaxhighlight lang="purebasic">For i=2008 To 2037
If DayOfWeek(Date(i,12,25,0,0,0))=0
PrintN(Str(i))
EndIf
Next</syntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">FOR yr = 2008 TO 2121
IF wd(12, 25, yr) = 0 THEN PRINT "Dec 25 "; yr
NEXT yr
END
 
FUNCTION wd (m, d, y)
IF m < 3 THEN
LET m = m + 12
LET y = y - 1
END IF
wd = ((y + INT(y / 4) - INT(y / 100) + INT(y / 400) + d + INT((153 * m + 8) / 5)) MOD 7)
END FUNCTION</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|QL SuperBASIC}}===
<b>Works with:</b> [https://en.wikipedia.org/wiki/Sinclair_QL ''Sinclair QL''] <br>
...having a structured [https://en.wikipedia.org/wiki/SuperBASIC ''BASIC''] with MOD and quite unlike the ZX81's "first-generation"
BASIC that's rather like using a calculator (also without an integer type). Even so, it's worth the minor effort to optimise the
code for the task at hand, as done below - which if implemented for the ZX81's routine would make it finish in a fraction of a
second, even in SLOW mode, as multiplying by 13 with a division by 5 is slower than by 256 alone, as well as that two divisions by
multiples of 100 are much slower than one by 16 as at the link. N.B. by relying on strings to have 4-digit years, this routine is not y10k-compliant
<syntaxhighlight lang="qbasic">
AUTO 100,10
DEF PROC Iso(S,O)
REM passing starting & ending years via integers S & O
LOCal y$,m%,d%,i$,n%,w%
LET m%=12 : d%=25
REM m% & d% are constants, so avoid recalculating n% (=48) each iteration
LET i$=m%*256+ 19300 : n%=i$(2 TO 3)+ d%
FOR count=S TO O
LET y$=count : w%=(y$(1 TO 2)&"32"DIV 16+ count DIV 4+ count+ n%)MOD 7
REM otherwise w%=(y$(1 TO 2)&"16"DIV 16+ count DIV 4+ count)MOD 7
REM = further optimisation beyond skipping irrelevant years:
IF w%=0 THEN PRINT count : count = count+ 4
END FOR count
END DEF Iso
 
ctrl+space
</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
==={{header|Quite BASIC}}===
The [[#MSX Basic|MSX Basic]] solution works without any changes.
 
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">for year = 2008 to 2121
if val(date$("12-25-";year)) mod 7 = 5 then print "For ";year;"xmas is Sunday"
next year</syntaxhighlight><pre>
For 2011 xmas is Sunday
For 2016 xmas is Sunday
For 2022 xmas is Sunday
For 2033 xmas is Sunday
For 2039 xmas is Sunday
For 2044 xmas is Sunday
For 2050 xmas is Sunday
For 2061 xmas is Sunday
For 2067 xmas is Sunday
For 2072 xmas is Sunday
For 2078 xmas is Sunday
For 2089 xmas is Sunday
For 2095 xmas is Sunday
For 2101 xmas is Sunday
For 2107 xmas is Sunday
For 2112 xmas is Sunday
For 2118 xmas is Sunday
</pre>
 
==={{header|S-BASIC}}===
<syntaxhighlight lang="basic">
$constant SUNDAY = 0
 
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
 
rem - main program
var year = integer
print "Christmas will fall on a Sunday in"
for year=2008 to 2121
if dayofweek(12,25,year) = SUNDAY then
print year
next year
end
</syntaxhighlight>
{{out}}
<pre>Christmas will fall on a Sunday in
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
==={{header|Sinclair ZX81 BASIC}}===
{{trans|C}}
Works with 1k of RAM. Follows the C code quite closely: the only factors that perhaps make it less readable are (a) the absence of a modulo operator and (b) the need for continual calls to <code>INT</code> because we don't have an integer type. The performance is pretty acceptable; seconds rather than minutes.
<langsyntaxhighlight lang="zxbasic"> 10 LET M=12
20 LET D=25
30 FOR Y=2008 TO 2121
Line 796 ⟶ 1,169:
110 LET W=D+INT ((13*MM-1)/5)+YY+INT (YY/4)-INT (YY/100)+INT (YY/400)
120 LET W=W-7*INT (W/7)
130 RETURN</langsyntaxhighlight>
{{out}}
<pre>2011
Line 816 ⟶ 1,189:
2118</pre>
 
==={{header|QLTI-83 SuperBASICBASIC}}===
{{Works with|TI-84+/SE}} only
<b>Works with:</b> [https://en.wikipedia.org/wiki/Sinclair_QL ''Sinclair QL''] <br>
<syntaxhighlight lang="ti83b">
...having a structured [https://en.wikipedia.org/wiki/SuperBASIC ''BASIC''] with MOD and quite unlike the ZX81's "first-generation"
:For(A,2008,2121
BASIC that's rather like using a calculator (also without an integer type). Even so, it's worth the minor effort to optimise the
:If dayofWk(A,12,25)=1
code for the task at hand, as done below - which if implemented for the ZX81's routine would make it finish in a fraction of a
:Disp A
second, even in SLOW mode, as multiplying by 13 with a division by 5 is slower than by 256 alone, as well as that two divisions by
:End
multiples of 100 are much slower than one by 16 as at the link. N.B. by relying on strings to have 4-digit years, this routine is not y10k-compliant
</syntaxhighlight>
<lang qbasic>
AUTO 100,10
DEF PROC Iso(S,O)
REM passing starting & ending years via integers S & O
LOCal y$,m%,d%,i$,n%,w%
LET m%=12 : d%=25
REM m% & d% are constants, so avoid recalculating n% (=48) each iteration
LET i$=m%*256+ 19300 : n%=i$(2 TO 3)+ d%
FOR count=S TO O
LET y$=count : w%=(y$(1 TO 2)&"32"DIV 16+ count DIV 4+ count+ n%)MOD 7
REM otherwise w%=(y$(1 TO 2)&"16"DIV 16+ count DIV 4+ count)MOD 7
REM = further optimisation beyond skipping irrelevant years:
IF w%=0 THEN PRINT count : count = count+ 4
END FOR count
END DEF Iso
 
ctrl+space
</lang>
{{out}}
<pre>2011
Line 860 ⟶ 1,214:
2107
2112
2118</pre>
Done</pre>
 
==={{header|Tiny BASIC}}===
{{works with|TinyBasic}}
<lang tinybasic>
<syntaxhighlight lang="basic">10 REM Day of the week
LET Y = 2007
20 LET MY = 122007
30 LET DM = 2512
40 LET D = 25
10 IF Y = 2122 THEN END
50 LETIF Y = Y2122 +THEN 1END
60 LET Y = GOSUBY 100+ 1
70 GOSUB 200
IF Z = 0 THEN PRINT Y
80 IF Z = GOTO0 10THEN PRINT Y
90 GOTO 50
 
100170 REM CALCULATECalculate DAYday OFof WEEKweek Z GIVENgiven
180 REM YEARyear Y, MONTHmonth M, ANDand DAYday D
190 REM SUNDAYSunday = 0, SATURDAYSaturday = 6
200 IF M < 3 THEN LET Y = Y - 1
210 IF M < 3 THEN LET M = M + 12
220 LET Z = Y + Y / 4 - Y / 100 + Y / 400
230 LET Z = Z + D + (153 * M + 8) / 5
240 LET Z = Z - 7 * (Z / 7)
250 RETURN</langsyntaxhighlight>
{{out}}
<pre>2011
Line 900 ⟶ 1,255:
2112
2118</pre>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">FUNCTION wd (m, d, y)
IF m < 3 THEN
LET m = m + 12
LET y = y - 1
END IF
LET wd = REMAINDER ((y + INT(y / 4) - INT(y / 100) + INT(y / 400) + d + INT((153 * m + 8) / 5)), 7)
END FUNCTION
 
FOR yr = 2008 TO 2121
IF wd(12, 25, yr) = 0 THEN PRINT "Dec 25 "; yr
NEXT yr
END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|VBA}}===
<syntaxhighlight lang="vb">Option Explicit
 
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
 
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function</syntaxhighlight>
 
{{Out}}
<pre>Xmas will be a Sunday in : 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118</pre>
 
==={{header|VBScript}}===
<syntaxhighlight lang="vb">For year = 2008 To 2121
If Weekday(DateSerial(year, 12, 25)) = 1 Then
WScript.Echo year
End If
Next</syntaxhighlight>
{{Out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">PROGRAM "progname"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
DECLARE FUNCTION wd (m, d, y)
 
FUNCTION Entry ()
FOR yr = 2008 TO 2121
IF wd(12, 25, yr) = 0 THEN PRINT "Dec 25 "; yr
NEXT yr
 
END FUNCTION
 
FUNCTION wd (m, d, y)
IF m < 3 THEN
m = m + 12
DEC y
END IF
RETURN ((y + INT(y / 4) - INT(y / 100) + INT(y / 400) + d + INT((153 * m + 8) / 5)) MOD 7)
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">sub wd(m, d, y)
If m < 3 Then // If m = 1 Or m = 2 Then
m = m + 12
y = y - 1
End If
Return mod((y + int(y / 4) - int(y / 100) + int(y / 400) + d + int((153 * m + 8) / 5)), 7)
End sub
// ------=< MAIN >=------
For yr = 2008 To 2121
If wd(12, 25, yr) = 0 Then
Print "Dec 25 ", yr
EndIf
Next</syntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="zxbasic">10 CLS
20 FOR y=2008 TO 2121
30 LET year=y: LET m=12: LET d=25: GO SUB 1000
40 IF wd=0 THEN PRINT d;" ";m;" ";y
50 NEXT y
60 STOP
1000 REM week day
1010 IF m=1 OR m=2 THEN LET m=m+12: LET year=year-1
1020 LET wd=FN m(year+INT (year/4)-INT (year/100)+INT (year/400)+d+INT ((153*m+8)/5),7)
1030 RETURN
1100 DEF FN m(a,b)=a-INT (a/b)*b</syntaxhighlight>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">:: Day of the Week task from Rosetta Code
:: Batch File Implementation
:: Question: In what years between 2008 and 2121 will the 25th of December be a Sunday?
Line 922 ⟶ 1,396:
)
pause
exit /b 0</langsyntaxhighlight>
{{out}}
<pre>Dec 25, 2011 is a Sunday.
Line 942 ⟶ 1,416:
Dec 25, 2118 is a Sunday.
Press any key to continue . . .</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT</lang>
 
=={{header|bc}}==
Because ''bc'' has no date library, this program uses [http://mathforum.org/library/drmath/view/62324.html ''Zeller's rule''], also known as [http://www.merlyn.demon.co.uk/zel-like.htm ''Zeller's congruence''], to calculate day of week.
 
<langsyntaxhighlight lang="bc">scale = 0
 
/*
Line 977 ⟶ 1,441:
if (w(y, 12, 25) == 0) y
}
quit</langsyntaxhighlight>
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let weekday(y, m, d) =
Line 991 ⟶ 1,455:
for year = 2008 to 2121
if weekday(year, 12, 25) = 0
do writef("%N*N", year)</langsyntaxhighlight>
{{out}}
<pre>2011
Line 1,014 ⟶ 1,478:
Befunge doesn't have any standard date-handling functionality, so we calculate the day of the week directly using a simple variation of the Zeller rule.
 
<langsyntaxhighlight lang="befunge">8 >:"2("*+::::4/+\"d"/-\45v
@_^#`"y": +1$<_v#%7+1+/*:*<
>:#,_>$:.55+,^ >0" ,52 ceD"</langsyntaxhighlight>
 
{{out}}
Line 1,039 ⟶ 1,503:
=={{header|Bracmat}}==
{{trans|C}}
<langsyntaxhighlight lang="bracmat">{ Calculate day of week in proleptic Gregorian calendar. Sunday == 0. }
( wday
= year month day adjustment mm yy
Line 1,065 ⟶ 1,529:
& 1+!y:?y
)
& done;</langsyntaxhighlight>
{{out}}
<pre>2011-12-25
Line 1,088 ⟶ 1,552:
Because of problems with various C libraries (such as ''time_t'' overflowing during 2038, or strptime() or mktime() not filling in ''tm_wday''), this program uses [http://mathforum.org/library/drmath/view/62324.html Zeller's Rule] to calculate day of week.
 
<langsyntaxhighlight lang="c">#include <stdio.h>
 
/* Calculate day of week in proleptic Gregorian calendar. Sunday == 0. */
Line 1,111 ⟶ 1,575:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
class Program
Line 1,129 ⟶ 1,593:
}
}
}</langsyntaxhighlight>
 
Using LINQ:
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 1,146 ⟶ 1,610:
foreach (string day in days) Console.WriteLine(day);
}
}</langsyntaxhighlight>Lambda expressions FTW:
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 1,159 ⟶ 1,623:
.ForEach(ent => Console.WriteLine(ent.ToString("dd MMM yyyy")));
}
}</langsyntaxhighlight>
{{out}}
<pre style="height:20ex;overflow:scroll">25 Dec 2011
Line 1,180 ⟶ 1,644:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <boost/date_time/gregorian/gregorian.hppchrono>
#include <ranges>
#include <iostream>
 
int main( ) {
std::cout << "Yuletide holidays must be allowed in the following years:\n";
using namespace boost::gregorian ;
for (int year : std::views::iota(2008, 2121)
 
| std::views::filter([](auto year) {
std::cout
if (std::chrono::weekday{
<< "Yuletide holidays must be allowed in the following years:\n" ;
std::chrono::year{year}/std::chrono::December/25}
for ( int i = 2008 ; i < 2121 ; i++ ) {
== std::chrono::Sunday) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) return true;
if ( d.day_of_week( ) == Sunday ) { }
return false;
std::cout << i << std::endl ;
})) {
std::cout << year << '\n';
}
}
std::cout << "\n" ;
}</syntaxhighlight>
return 0 ;
}</lang>
{{out}}
<pre>
Line 1,223 ⟶ 1,687:
Utilizing Java interop
 
<syntaxhighlight lang="clojure">(import '[java.util GregorianCalendar])
<lang clojure>
(import '(java.util GregorianCalendar))
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= (. (new GregorianCalendar %
(filter #(= GregorianCalendar/SUNDAY
(. GregorianCalendar DECEMBER) 25) get (. GregorianCalendar DAY_OF_WEEK))
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
(. GregorianCalendar SUNDAY)) (range start (inc end))))
GregorianCalendar/DAY_OF_WEEK)))))
 
(println (yuletide 2008 2121))
</syntaxhighlight>
</lang>
 
{{out}}
<pre>(2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</pre>
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">weekday = proc (d: date) returns (int)
y: int := d.year
m: int := d.month
Line 1,255 ⟶ 1,721:
end
end
end start_up</langsyntaxhighlight>
{{out}}
<pre>2011
Line 1,277 ⟶ 1,743:
=={{header|COBOL}}==
Using Date Intrinsic Functions
<syntaxhighlight lang="cobol">
<lang COBOL>
program-id. dec25.
data division.
Line 1,300 ⟶ 1,766:
.
end program dec25.
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:20ex;overflow:scroll">
Line 1,324 ⟶ 1,790:
Without Date Intrinsic Functions
 
<syntaxhighlight lang="cobol">
<lang Cobol>
identification division.
program-id. dowtest.
Line 1,393 ⟶ 1,859:
.
end program todow.
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:20ex;overflow:scroll">
Line 1,416 ⟶ 1,882:
 
=={{header|CoffeeScript}}==
<langsyntaxhighlight lang="coffeescript">december = 11 # gotta love Date APIs :)
sunday = 0
for year in [2008..2121]
xmas = new Date year, december, 25
console.log year if xmas.getDay() is sunday</langsyntaxhighlight>one-liner:<syntaxhighlight lang ="coffeescript">console.log year for year in [2008...2121] when new Date(year, 11, 25).getDay() is 0</langsyntaxhighlight>
{{out}}
<pre style="height:20ex;overflow:scroll">
Line 1,443 ⟶ 1,909:
 
=={{header|ColdFusion}}==
<syntaxhighlight lang="coldfusion">
<lang ColdFusion>
<cfloop from = "2008" to = "2121" index = "i">
<cfset myDate = createDate(i, 12, 25) />
Line 1,450 ⟶ 1,916:
</cfif>
</cfloop>
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
Line 1,459 ⟶ 1,925:
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)</langsyntaxhighlight>
 
<langsyntaxhighlight lang="lisp">(loop for year from 2008 upto 2121
for xmas = (encode-universal-time 0 0 0 25 12 year)
for day = (nth-value 6 (decode-universal-time xmas))
when (= day 6) collect year)</langsyntaxhighlight>
 
=={{header|Component Pascal}}==
{{Works with|BlackBox Component Builder}}
<langsyntaxhighlight lang="oberon2">
MODULE DayOfWeek;
IMPORT DevCommanders, TextMappers, Dates, StdLog;
Line 1,506 ⟶ 1,972:
 
END DayOfWeek.
</syntaxhighlight>
</lang>
Execute: ^Q DayOfWeek.Do 2008 2121~
{{out}}
Line 1,530 ⟶ 1,996:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub weekday(year: uint16, month: uint8, day: uint8): (wd: uint8) is
Line 1,553 ⟶ 2,019:
end if;
year := year + 1;
end loop;</langsyntaxhighlight>
{{out}}
<pre>2011
Line 1,575 ⟶ 2,041:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
 
Line 1,581 ⟶ 2,047:
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}</langsyntaxhighlight>
{{out}}
<pre>Christmas comes on a Sunday in the years:
Line 1,588 ⟶ 2,054:
=={{header|Delphi}}==
{{libheader|sysutils}} always in uses clause in Delphi
<langsyntaxhighlight lang="delphi">procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
Line 1,607 ⟶ 2,073:
//GUI
form1.label1.caption := outputyears;
end;</langsyntaxhighlight>
 
Procedure called with year range to test and outputs a space-delimited array of years to a label. There is no error check that fromyear < toyear, but this is easily added.
Line 1,617 ⟶ 2,083:
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">proc nonrec weekday(word y, m, d) byte:
word c;
if m<3 then
Line 1,637 ⟶ 2,103:
fi
od
corp</langsyntaxhighlight>
{{out}}
<pre>2011
Line 1,656 ⟶ 2,122:
2112
2118</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
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
centuryDoomsday = 2
elif century mod 4 = 1
centuryDoomsday = 0
elif century mod 4 = 2
centuryDoomsday = 5
elif century mod 4 = 3
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
leap = 1
else
leap = 0
.
else
if mainYear mod 4 = 0
leap = 1
else
leap = 0
.
.
# 4. Calculate the DOTW of January 1
if leap = 1
januaryOne = (yearDoomsday + 4) mod 7
else
januaryOne = (yearDoomsday + 5) mod 7
.
# 5. Determine the nth day of the year
if month = 1
NthDay = 0
elif month = 2
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
.
NthDay += day
# 6. Finally, calculate the day of the week
return (januaryOne + NthDay - 1) mod 7
.
for i = 2008 to 2121
if dayOfTheWeek i 12 25 = 0
print "Christmas in " & i & " is on Sunday"
.
.
</syntaxhighlight>
{{out}}
<pre>
Christmas in 2011 is on Sunday
Christmas in 2016 is on Sunday
Christmas in 2022 is on Sunday
Christmas in 2033 is on Sunday
Christmas in 2039 is on Sunday
Christmas in 2044 is on Sunday
Christmas in 2050 is on Sunday
Christmas in 2061 is on Sunday
Christmas in 2067 is on Sunday
Christmas in 2072 is on Sunday
Christmas in 2078 is on Sunday
Christmas in 2089 is on Sunday
Christmas in 2095 is on Sunday
Christmas in 2101 is on Sunday
Christmas in 2107 is on Sunday
Christmas in 2112 is on Sunday
Christmas in 2118 is on Sunday
</pre>
 
=={{header|ECL}}==
<langsyntaxhighlight ECLlang="ecl">//In what years between 2008 and 2121 will the 25th of December be a Sunday?
 
IMPORT STD;
Line 1,697 ⟶ 2,258:
2118
*/
</syntaxhighlight>
</lang>
This code solves a specific task, but can easily be modified as a generic function to return the DayOfWeek for any day after 1 AD.
 
=={{header|EDSAC order code}}==
Uses a version of Zeller's congruence that finds the day of the week for any Gregorian date up to 28 Feb 43699.
<syntaxhighlight lang="edsac">
[Day of week for Rosetta Code.]
[EDSAC program, Initial Orders 2.]
 
[Library subroutine M3 - prints header and is then overwritten.]
[Here, the last character sets the teleprinter to figures.]
PF GK IF AF RD LF UF OF E@ A6F G@ E8F EZ PF
*CHRISTMAS!DAY!ON!SUNDAY@&#
..PZ [blank tape, then resync]
 
[Subroutine to find day of week in Gregorian calendar, by Zeller's method.]
[This EDSAC implementation is valid up to and including 28 Feb 43699.]
[Input: 4F = year, 5F = month, 6F = day of month (all preserved).]
[Output: 7F = day of week: 0 = Saturday, 1 = Sunday, ..., 6 = Friday.]
[Workspace: 0F]
T128K GK
A3F T41@ [plant return link as usual]
[January and February are taken as months 13 and 14 of the previous year]
A5F [load month]
S43@ [subtract 3 to test for Jan or Feb]
E9@ [jump if not Jan or Feb]
A45@ [add 16 to make month + 1]
T7F [to 7F]
S42@ [acc := -1]
G11@ [join common code]
[9] A44@ [not Jan, Feb; make month + 1]
T7F [to 7F; acc := 0]
[11] A4F [here with acc = 0 or -1; add year]
TF [adjusted year to 0F]
H46@ [mult reg := 13/20 (near enough)]
V7F [times (month + 1)]
L1F [shift 2 left]
T7F [7F := 13*(month + 1) div 5]
AF [year]
R1F [shift 2 right]
AF [year + (year div 4)]
A7F [add into 7F]
T7F
H47@ [mult reg := 64/100 (approx, OK for dates as above)]
VF [times year]
R16F [shift 6 right]
UF [0F := year div 100]
R1F [shift 2 more right]
SF [(year div 400) - (year div 100)]
A6F [add day of month]
A7F [add into 7F]
T7F
[Finally take 7F modulo 7. Suppose 7F = 7*q + r (0 <= r < 7)]
H48@ [mult reg := 4/7 (near enough)]
V7F [acc := 4*q + (4/7)*r]
R1F [shift 2 right: acc := q + r/7]
TF [0F := acc high word = q]
H49@ [mult reg := 7/8 (exact)]
A7F [acc := 7*q + r]
R2F [shift 3 right, acc := (7*q + r)/8]
NF [subtract (7/8)*q, acc := r/8]
L2F [shift 3 left, acc := r as required]
T7F [return result r in 7F]
[41] ZF [(planted) jump back to caller]
[Constants]
[42] PD [1]
[43] P1D [3]
[44] P2F [4]
[45] P8F [16]
[46] J819D [0.A667 hex, approx 13/20]
[47] J492F [0.A3D8 hex, approx 64/100]
[48] O293F [0.924A hex, approx 4/7]
[49] KF [0.1110 hex = 7/8]
 
[Subroutine to print non-negative 17-bit integer.]
[Parameters: 0F = integer to be printed (not preserved)
1F = character for leading zero (preserved)]
[Workspace: 4F..7F, 38 locations]
T64K
GK A3F T34@ A1F T7F S35@ T6F T4#F AF T4F H36@ V4F RD A4#F R1024F H37@ E23@ O7F A2F
T6F T5F V4#F YF L8F T4#F A5F L1024F UF A6F G16@ OF TF T7F A6F G17@ ZF P4F Z219D TF
 
[Main routine]
T400K GK
[Constants]
[0] P1004F [2008]
[1] P1060D [2121]
[2] P6F [12 (December)]
[3] P12D [25]
[4] PD [1]
[5] @F [carriage return]
[6] &F [line feed]
[7] K4096F [null char]
[Variable]
[8] PF [year]
[Enter with acc = 0]
[9] A7@ T1F [1F := null for print subroutine]
A@ [load first year]
[12] U8@ T4F [save year, and pass to Zeller subroutine]
A2@ T5F [pass month 12 to Zeller subroutine]
A3@ T6F [pass day 25 to Zeller subroutine]
A18@ G128F [call Zeller subroutine]
A7F S4@ [load day of week, subtract 1]
G32@ [jump if day = 0]
S4@ E32@ [subtract 1, jump if day >= 2]
TF [here if day = 1 (Sunday); clear acc]
A4F TF [pass year to print subroutine]
A28@ G64F [call print subroutine (overwrites 4F)]
O5@ O6@ [print CR, LF]
[32] TF [common code; clear acc]
A8@ S1@ [test for end]
E39@ [jump to exit if so]
A1@ [restore acc after test]
A4@ E12@ [inc year and loop back]
[39] O7@ [done; print null]
ZF [halt the machine]
 
E9Z [define entry point]
PF [acc = 0 on entry]
[end]
</syntaxhighlight>
{{out}}
<pre>
CHRISTMAS DAY ON SUNDAY
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Elixir}}==
{{works with|Elixir|1.4}}
<langsyntaxhighlight lang="elixir">Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December #{year} is sunday"
end)</langsyntaxhighlight>
 
{{out}}
Line 1,729 ⟶ 2,430:
 
=={{header|Emacs Lisp}}==
<langsyntaxhighlight lang="lisp">(require 'calendar)
 
(defun sunday-p (y)
Line 1,739 ⟶ 2,440:
(seq-filter #'sunday-p (number-sequence a b)))
 
(print (xmas-sunday 2008 2121))</langsyntaxhighlight>
{{output}}
<pre>(2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</pre>
Line 1,745 ⟶ 2,446:
=={{header|Erlang}}==
 
<langsyntaxhighlight lang="erlang">% Implemented by bengt kleberg
-module(yuletide).
-export([main/0, sunday_years/2]).
Line 1,756 ⟶ 2,457:
 
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.</langsyntaxhighlight>
{{out}}
<pre>
Line 1,779 ⟶ 2,480:
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM DAY_OF_THE_WEEK
 
Line 1,809 ⟶ 2,510:
GET(K$)
END PROGRAM
</syntaxhighlight>
</lang>
{{out}}
<pre>Dec 25, 2011
Line 1,831 ⟶ 2,532:
 
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">
<lang Euphoria>
--Day of the week task from Rosetta Code wiki
--User:Lnettnay
Line 1,847 ⟶ 2,548:
end if
end for
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,870 ⟶ 2,571:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System
 
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"</langsyntaxhighlight>
{{out}}
<pre>[2011; 2016; 2022; 2033; 2039; 2044; 2050; 2061; 2067; 2072; 2078; 2089; 2095;
Line 1,880 ⟶ 2,581:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: calendar math.ranges prettyprint sequences ;
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .</langsyntaxhighlight>
 
=={{header|FBSL}}==
<lang qbasic>#APPTYPE CONSOLE
 
'In what years between 2008 and 2121 will the 25th of December be a Sunday?
dim date as integer, dayname as string
for dim year = 2008 to 2121
date = year * 10000 + 1225
dayname = dateconv(date,"dddd")
if dayname = "Sunday" then
print "Christmas Day is on a Sunday in ", year
end if
next
PAUSE
</lang>
 
=={{header|Forth}}==
 
Forth has only TIME&DATE, which does not give day of week. Many public Forth Julian date calculators had year-2100 problems, but this algorithm works well.
<langsyntaxhighlight lang="forth">
\ Zeller's Congruence
: weekday ( d m y -- wd) \ 1 mon..7 sun
Line 1,918 ⟶ 2,603:
7 = if i . then
loop cr ;
</syntaxhighlight>
</lang>
 
<langsyntaxhighlight lang="forth">
cr yuletide
December 25 is Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
ok
</syntaxhighlight>
</lang>
 
 
To show year-2100 problems with SwiftForth's provided Modified Julian Day support:
 
<langsyntaxhighlight lang="forth">: yuletide
." December 25 is Sunday in "
2122 2008 do
Line 1,937 ⟶ 2,622:
 
cr yuletide
December 25 is Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2100 2106 2117</langsyntaxhighlight>
 
In [[4tH]] a library is available which provides the right answer:
 
<langsyntaxhighlight lang="forth">include lib/time.4th
 
: yuletide
Line 1,950 ⟶ 2,635:
loop cr ;
 
cr yuletide</langsyntaxhighlight>
 
The code is derived from "Collected Algorithms from ACM", Volume 1 Algorithms 1-220.
Line 1,957 ⟶ 2,642:
{{works with|Fortran|90 and later}}
Based on Forth example
<langsyntaxhighlight lang="fortran">PROGRAM YULETIDE
IMPLICIT NONE
Line 1,986 ⟶ 2,671:
END FUNCTION Day_of_week
END PROGRAM YULETIDE</langsyntaxhighlight>
{{out}}
<pre>
Line 1,994 ⟶ 2,679:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Day_of_the_week}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Day of the week 01.png]]
In '''[https://formulae.org/?example=Day_of_the_week this]''' page you can see the program(s) related to this task and their results.
 
[[File:Fōrmulæ - Day of the week 02.png]]
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">for y = 2008 to 2121
if (parseDate["$y-12-25"] -> ### u ###) == "7"
println[y]</langsyntaxhighlight>
 
{{out}}
Line 2,024 ⟶ 2,711:
2112
2118
</pre>
 
=={{header|FutureBasic}}==
<lang futurebasic>window 1
 
long y
CFDateRef dt
NSInteger day
CFCalendarRef cal
DateComponentsRef comps
 
cal = fn CalendarCurrent
 
comps = fn DateComponentsInit
DateComponentsSetMonth( comps, 12 )
DateComponentsSetDay( comps, 25 )
 
for y = 2008 to 2121
DateComponentsSetYear( comps, y )
dt = fn CalendarDateFromComponents( cal, comps )
day = fn CalendarComponentFromDate( cal, NSCalendarUnitWeekday, dt )
if ( day == 1 )
print y
end if
next
 
HandleEvents</lang>
 
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=b9b4e9a871e96ea6f1db467fa23669fe Click this link to run this code]'''
<lang gambas>Public Sub Main()
Dim siCount As Short
 
For siCount = 2008 To 2121
If WeekDay(Date(siCount, 12, 25)) = 0 Then Print Format(Date(siCount, 12, 25), "dddd dd mmmm yyyy") & " falls on a Sunday"
Next
 
End</lang>
Output:
<pre>
Sunday 25 December 2011 falls on a Sunday
Sunday 25 December 2016 falls on a Sunday
Sunday 25 December 2022 falls on a Sunday
Sunday 25 December 2033 falls on a Sunday
Sunday 25 December 2039 falls on a Sunday
Sunday 25 December 2044 falls on a Sunday
Sunday 25 December 2050 falls on a Sunday
Sunday 25 December 2061 falls on a Sunday
Sunday 25 December 2067 falls on a Sunday
Sunday 25 December 2072 falls on a Sunday
Sunday 25 December 2078 falls on a Sunday
Sunday 25 December 2089 falls on a Sunday
Sunday 25 December 2095 falls on a Sunday
Sunday 25 December 2101 falls on a Sunday
Sunday 25 December 2107 falls on a Sunday
Sunday 25 December 2112 falls on a Sunday
Sunday 25 December 2118 falls on a Sunday
</pre>
 
=={{header|GAP}}==
<langsyntaxhighlight lang="gap">Filtered([2008 .. 2121], y -> WeekDay([25, 12, y]) = "Sun");
# [ 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118 ]
 
Line 2,107 ⟶ 2,736:
 
Filtered([2008 .. 2121], y -> WeekDayAlt([25, 12, y]) = "Sun");
# [ 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118 ]</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 2,122 ⟶ 2,751:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,147 ⟶ 2,776:
 
Solution:
<langsyntaxhighlight lang="groovy">def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "Sun" } }</langsyntaxhighlight>
 
Test program:
<syntaxhighlight lang ="groovy">println yuletide(2008, 2121)</langsyntaxhighlight>
 
{{out}}
Line 2,157 ⟶ 2,786:
=={{header|Haskell}}==
Using the time library:
<langsyntaxhighlight lang="haskell">import Data.Time (fromGregorian)
import Data.Time.Calendar.WeekDate (toWeekDate)
 
Line 2,176 ⟶ 2,805:
| year <- [2008 .. 2121],
isXmasSunday year
]</langsyntaxhighlight>
{{out}}
<pre>Sunday 25 December 2011
Line 2,197 ⟶ 2,826:
 
The built-in System.Time module can overflow at the Unix epoch in 2038:
<langsyntaxhighlight lang="haskell">import System.Time
isXmasSunday :: Int -> Bool
Line 2,225 ⟶ 2,854:
[ "25 December " ++ show year ++ " is Sunday"
| year <- [2008 .. 2121]
, isXmasSunday year ]</langsyntaxhighlight>
{{out}} on 32-bit machine:
<pre>
Line 2,255 ⟶ 2,884:
 
=={{header|HicEst}}==
<langsyntaxhighlight HicEstlang="hicest">DO year = 1, 1000000
TIME(Year=year, MOnth=12, Day=25, TO, WeekDay=weekday)
IF( weekday == 7) WRITE(StatusBar) year
ENDDO
 
END</langsyntaxhighlight>
<pre>No anomalies detected for the first million years :-)
Dec 25 = Sunday in
Line 2,269 ⟶ 2,898:
=={{header|Icon}} and {{header|Unicon}}==
 
<langsyntaxhighlight Iconlang="icon">link datetime
 
procedure main()
writes("December 25th is a Sunday in: ")
every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ")
end</langsyntaxhighlight>
 
 
Line 2,280 ⟶ 2,909:
[http://www.cs.arizona.edu/icon/library/src/procs/datetime.icn datetime provides dayoweek]
 
<langsyntaxhighlight Iconlang="icon">procedure dayoweek(day, month, year) #: day of the week
static d_code, c_code, m_code, ml_code, y, C, M, Y
 
Line 2,322 ⟶ 2,951:
return d_code[(C + Y + M + day) % 7 + 1]
end</langsyntaxhighlight>
 
{{out}}
Line 2,328 ⟶ 2,957:
 
=={{header|J}}==
<langsyntaxhighlight lang="j"> load 'dates' NB. provides verb 'weekday'
xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] NB. returns years where 25 Dec is a Sunday
xmasSunday 2008 + i.114 NB. check years from 2008 to 2121
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</langsyntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
<lang java>import java.util.Calendar;
import static java.util.Calendar.*;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
Line 2,340 ⟶ 2,971:
public class Yuletide{
public static void main(String[] args) {
Calendar calendar;
for(int i = 2008;i<=2121;i++){
int count = 1;
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
for (int year = 2008; year <= 2121; year++) {
25);
calendar = new GregorianCalendar(year, DECEMBER, 25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
if (calendar.get(DAY_OF_WEEK) == SUNDAY) {
System.out.println(cal.getTime());
if (count != 1)
}
System.out.print(", ");
}
System.out.printf("%d", calendar.get(YEAR));
count++;
}
}
}
}
}</lang>
</syntaxhighlight>
{{out}}
<pre>
<pre>Sun Dec 25 00:00:00 CST 2011
2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
Sun Dec 25 00:00:00 CST 2016
</pre>
Sun Dec 25 00:00:00 CST 2022
Sun Dec 25 00:00:00 CST 2033
Sun Dec 25 00:00:00 CST 2039
Sun Dec 25 00:00:00 CST 2044
Sun Dec 25 00:00:00 CST 2050
Sun Dec 25 00:00:00 CST 2061
Sun Dec 25 00:00:00 CST 2067
Sun Dec 25 00:00:00 CST 2072
Sun Dec 25 00:00:00 CST 2078
Sun Dec 25 00:00:00 CST 2089
Sun Dec 25 00:00:00 CST 2095
Sun Dec 25 00:00:00 CST 2101
Sun Dec 25 00:00:00 CST 2107
Sun Dec 25 00:00:00 CST 2112
Sun Dec 25 00:00:00 CST 2118</pre>
 
=={{header|JavaScript}}==
Line 2,372 ⟶ 2,994:
===ES5===
====Iteration====
<langsyntaxhighlight lang="javascript">for (var year = 2008; year <= 2121; year++){
var xmas = new Date(year, 11, 25)
if ( xmas.getDay() === 0 )
console.log(year)
}</langsyntaxhighlight>
{{out}}
<pre>2011
Line 2,398 ⟶ 3,020:
====Functional composition====
 
<langsyntaxhighlight JavaScriptlang="javascript">(function () {
'use strict';
 
Line 2,418 ⟶ 3,040:
.filter(isXmasSunday);
 
})();</langsyntaxhighlight>
 
{{Out}}
Line 2,425 ⟶ 3,047:
 
===ES6===
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
"use strict";
 
Line 2,455 ⟶ 3,077:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<langsyntaxhighlight JavaScriptlang="javascript">[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</langsyntaxhighlight>
 
=={{header|jq}}==
<langsyntaxhighlight lang="jq"># Use Zeller's Congruence to determine the day of the week, given
# year, month and day as integers in the conventional way.
# If iso == "iso" or "ISO", then emit an integer in 1 -- 7 where
Line 2,477 ⟶ 3,099:
| if iso == "iso" or iso == "ISO" then 1 + ((. + 5) % 7)
else . % 7
end;</langsyntaxhighlight>
'''The task''':
<langsyntaxhighlight lang="jq"># Give the results as an array so they can
# readily be presented on a single line:
[range(2008; 2122) | select( day_of_week(.;12;25;0) == 1 )]</langsyntaxhighlight>
{{out}}
$ jq -n -c -f zeller.jq
Line 2,489 ⟶ 3,111:
Jsi does not yet implement the Javascript ''Date'' object. ''strftime' and ''strptime'' functions are used here instead.
 
<langsyntaxhighlight lang="javascript">/* Day of the week, December 25th on a Sunday */
for (var year = 2008; year <= 2121; year++) {
var xmas = strptime(year + '/12/25', '%Y/%m/%d');
Line 2,516 ⟶ 3,138:
2118
=!EXPECTEND!=
*/</langsyntaxhighlight>
 
{{out}}
Line 2,523 ⟶ 3,145:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Dates
 
lo, hi = 2008, 2121
Line 2,532 ⟶ 3,154:
 
println("Years from $lo to $hi having Christmas on Sunday: ")
foreach(println, year.(xmas))</langsyntaxhighlight>
 
{{out}}
Line 2,555 ⟶ 3,177:
 
=={{header|K}}==
<langsyntaxhighlight Klang="k"> wd:{(__jd x)!7} / Julian day count, Sun=6
y@&6={wd 1225+x*10000}'y:2008+!114
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</syntaxhighlight>
</lang>
 
=={{header|Koka}}==
<syntaxhighlight lang="koka">
import std/time/date
import std/time/calendar
import std/time/instant
import std/time/utc
 
fun main()
for(2008, 2121) fn(year)
val i = instant(year, 12, 25, cal=cal-gregorian)
val dow = (i.days+6)%7 // plus 6 since 2000-01-01 epoch was a Saturday
match dow.weekday
Sun -> println(year.show)
_ -> ()
</syntaxhighlight>
 
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
import java.util.*
Line 2,572 ⟶ 3,231:
calendar.add(Calendar.YEAR, 1)
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,596 ⟶ 3,255:
2118
</pre>
 
=={{header|Lambdatalk}}==
{{trans|Javascript}}
<syntaxhighlight lang="javascript">
 
{xmasOnSunday 2008 2121}
->
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
 
{script
LAMBDATALK.DICT["xmasOnSunday"] = function() {
var args = arguments[0].trim().split(" "),
days = [];
 
for (var year = args[0]; year <= args[1]; year++) {
var xmas = new Date(year, 11, 25)
if ( xmas.getDay() === 0 )
days.push(year)
}
 
return days.join("\n")
};
}
 
 
</syntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight lang="lasso">loop(-From=2008, -to=2121) => {^
local(tDate = date('12/25/' + loop_count))
#tDate->dayOfWeek == 1 ? '\r' + #tDate->format('%D') + ' is a Sunday'
^}</langsyntaxhighlight>
 
{{out}}
Line 2,621 ⟶ 3,322:
12/25/2112 is a Sunday
12/25/2118 is a Sunday</pre>
 
=={{header|Liberty BASIC}}==
<lang lb> count = 0
for year = 2008 to 2121
dateString$="12/25/";year
dayNumber=date$(dateString$)
 
if dayNumber mod 7 = 5 then
count = count + 1
print dateString$
end if
 
next year
 
print count; " years when Christmas Day falls on a Sunday"
end</lang>
 
=={{header|Lingo}}==
<langsyntaxhighlight lang="lingo">put "December 25 is a Sunday in:"
refDateObj = date(1905,1,2)
repeat with year = 2008 to 2121
Line 2,645 ⟶ 3,330:
dayOfWeek = ((dateObj - refDateObj) mod 7)+1 -- 1=Monday..7=Sunday
if dayOfWeek=7 then put year
end repeat</langsyntaxhighlight>
{{out}}
<pre>
Line 2,669 ⟶ 3,354:
 
=={{header|LiveCode}}==
<langsyntaxhighlight LiveCodelang="livecode">function xmasSunday startDate endDate
convert the long date to dateitems
put it into xmasDay
Line 2,681 ⟶ 3,366:
if the last char of xmasYear is comma then delete the last char of xmasYear
return xmasYear
end xmasSunday</langsyntaxhighlight>Example<syntaxhighlight lang LiveCode="livecode">put xmasSunday(2008,2121)</langsyntaxhighlight>Output<pre>2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118</pre>
 
=={{header|Logo}}==
<langsyntaxhighlight Logolang="logo">; Determine if a Gregorian calendar year is leap
to leap? :year
output (and
Line 2,717 ⟶ 3,402:
; Put it all together to answer the question posed in the problem
print filter [sunday? ? 12 25] iseq 2008 2121
bye</langsyntaxhighlight>
 
{{Out}}
Line 2,725 ⟶ 3,410:
'''Library:''' [http://luaforge.net/projects/date/ LuaDate]
 
<langsyntaxhighlight Lualang="lua">require("date")
 
for year=2008,2121 do
Line 2,731 ⟶ 3,416:
print(year)
end
end</langsyntaxhighlight>
 
{{out}}
Line 2,756 ⟶ 3,441:
=== Without external modules ===
Same output as above
<langsyntaxhighlight Lualang="lua">local dTab = {day = 25, month = 12}
for year = 2008, 2121 do
dTab.year = year
Line 2,762 ⟶ 3,447:
print(year)
end
end</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Str$( number, format$) use Visual Basic 6 format
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Print "December 25 is a Sunday in:"
For Year=2008 to 2121 {
Line 2,782 ⟶ 3,467:
 
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,805 ⟶ 3,490:
 
=={{header|M4}}==
<langsyntaxhighlight M4lang="m4">divert(-1)
 
define(`for',
Line 2,823 ⟶ 3,508:
 
for(`yr',2008,2121,
`ifelse(eval(julianxmas(yr)%7==6),1,`yr ')')</langsyntaxhighlight>
 
{{out}}
Line 2,832 ⟶ 3,517:
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">xmas:= proc()
local i, dt;
for i from 2008 to 2121 by 1 do
Line 2,842 ⟶ 3,527:
end proc;
 
xmas();</langsyntaxhighlight>
 
{{Out|Output}}
Line 2,867 ⟶ 3,552:
Or simply:
 
<langsyntaxhighlight lang="maple">select(y->Calendar:-DayOfWeek(Date(y,12,25))=1,[$2008..2121]);</langsyntaxhighlight>
 
{{out}}
Line 2,873 ⟶ 3,558:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]</langsyntaxhighlight>
gives back:
<langsyntaxhighlight Mathematicalang="mathematica">{2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118}</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<langsyntaxhighlight Matlablang="matlab"> t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]);
t = t(strmatch('Sunday', datestr(t,'dddd')), :);
datestr(t,'yyyy')
</syntaxhighlight>
</lang>
 
 
Line 2,907 ⟶ 3,592:
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">weekday(year, month, day) := block([m: month, y: year, k],
if m < 3 then (m: m + 12, y: y - 1),
k: 1 + remainder(day + quotient((m + 1)*26, 10) + y + quotient(y, 4)
Line 2,916 ⟶ 3,601:
sublist(makelist(i, i, 2008, 2121),
lambda([y], weekday(y, 12, 25) = 'sunday));
/* [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118] */</langsyntaxhighlight>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">import "dateTime"
 
print "Years between 2008 and 2121 when 25th December falls on Sunday:"
years = []
for year in range(2008, 2121)
date = year + "-12-25"
if dateTime.weekday(date) == 0 then years.push year
end for
print years.join(", ")</syntaxhighlight>
 
{{out}}
<pre>Years between 2008 and 2121 when 25th December falls on Sunday:
2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
</pre>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">П9 7 П7 1 П8 НОП ИП8 2 2 -
1 0 / [x] П6 ИП9 + 1 8 9
9 - 3 6 5 , 2 5 * [x]
Line 2,925 ⟶ 3,626:
0 , 5 9 * [x] + 2 9 +
ИП7 + П4 ИП4 7 / [x] 7 * -
x=0 64 ИП9 С/П ИП9 1 + П9 БП 06</langsyntaxhighlight>
 
''Input:'' РX: starting year.
Line 2,937 ⟶ 3,638:
Consequently, it suffers from the same problem as C.
 
<langsyntaxhighlight lang="modula3">MODULE Yule EXPORTS Main;
 
IMPORT IO, Fmt, Date, Time;
Line 2,964 ⟶ 3,665:
END;
END;
END Yule.</langsyntaxhighlight>
 
{{out}}
Line 2,977 ⟶ 3,678:
=={{header|MUMPS}}==
{{libheader|VA Kernel|22.0}}
<syntaxhighlight lang="mumps">
<lang MUMPS>
DOWHOLIDAY
;In what years between 2008 and 2121 will December 25 be a Sunday?
Line 2,997 ⟶ 3,698:
KILL BDT,EDT,CHECK,CHKFOR,LIST,I,X,Y
QUIT
</langsyntaxhighlight>Usage:<pre>USER>D ^DOW
The following years have Christmas on a Sunday: 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
Line 3,003 ⟶ 3,704:
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">import Nanoquery.Util
// loop through the years 2008 through 2121
Line 3,010 ⟶ 3,711:
println "In " + year + ", December 25th is a Sunday."
end if
end for</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
Line 3,031 ⟶ 3,732:
 
return
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,039 ⟶ 3,740:
===Comparison of Some Common Day-of-Week Algorithms===
The following program exercises some common &quot;Day-0f-Week&quot; algorithms to confirm they all arrive at the same result.
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
Line 3,230 ⟶ 3,931:
method modulo(N = int, D = int) inheritable static binary returns int
return (D + (N // D)) // D
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,244 ⟶ 3,945:
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import times
 
for year in 2008..2121:
if getDayOfWeek(25, mDec, year) == dSun:
stdout.write year, ' '
echo ""</langsyntaxhighlight>
 
{{out}}
Line 3,256 ⟶ 3,957:
=={{header|Oberon-2}}==
{{works with|oo2c version 2}}
<langsyntaxhighlight lang="oberon2">
MODULE DayOfWeek;
IMPORT NPCT:Dates, Out;
Line 3,270 ⟶ 3,971:
END
END DayOfWeek.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,292 ⟶ 3,993:
</pre>
{{works with|AOS}}
<syntaxhighlight lang="oberon2">
<lang Oberon2>
MODULE DaysOfWeek; (** AUTHOR ""; PURPOSE ""; *)
 
Line 3,312 ⟶ 4,013:
 
END DaysOfWeek.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,339 ⟶ 4,040:
{{works with|Cocoa}}
 
<langsyntaxhighlight lang="objc">#import <Foundation/Foundation.h>
 
int main()
Line 3,360 ⟶ 4,061:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 3,385 ⟶ 4,086:
=={{header|OCaml}}==
{{trans|C}}
<langsyntaxhighlight lang="ocaml">#load "unix.cma"
open Unix
 
Line 3,404 ⟶ 4,105:
raise e
done
with _ -> ()</langsyntaxhighlight>
 
{{out}} of a run on a 32 bit machine
Line 3,421 ⟶ 4,122:
Unlike the previous example which only uses the OCaml standard library, here with the OCaml Calendar Library we can go until the year 2121:
 
<langsyntaxhighlight lang="ocaml">open CalendarLib
 
let list_make_seq first last =
Line 3,438 ⟶ 4,139:
Date.day_of_week (Date.make year 12 25) = Date.Sun) years in
print_endline "December 25 is a Sunday in:";
List.iter (Printf.printf "%d\n") years</langsyntaxhighlight>
 
{{out}}
Line 3,463 ⟶ 4,164:
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">import: date
seqFrom(2008, 2121) filter(#[ 12 25 Date newDate dayOfWeek Date.SUNDAY == ]) .</langsyntaxhighlight>
{{out}}
<pre>
Line 3,472 ⟶ 4,173:
=={{header|ooRexx}}==
===Christmas===
<langsyntaxhighlight ooRexxlang="oorexx">date = .datetime~new(2008, 12, 25)
lastdate = .datetime~new(2121, 12, 25)
 
Line 3,484 ⟶ 4,185:
end
 
say "Christmas falls on Sunday in the years" resultList~toString("Line", ", ")</langsyntaxhighlight>
{{out}}
<pre>Christmas falls on Sunday in the years 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118</pre>
===Weekday===
<langsyntaxhighlight ooRexxlang="oorexx">/* REXX */
Parse Arg yyyymmdd
If arg(1)='' |,
Line 3,498 ⟶ 4,199:
wd=.Array~of('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')
dt=.DateTime~new(y,m,d)
say yyyymmdd 'is a' wd[dt~weekday]</langsyntaxhighlight>
{{out}}
<pre>H:\>rexx wd ?
Line 3,507 ⟶ 4,208:
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">
njd(D) =
{
Line 3,518 ⟶ 4,219:
 
for (y = 2008, 2121, if (njd([y,12,25]) % 7 == 1, print(y)));
</syntaxhighlight>
</lang>
 
Output:
Line 3,546 ⟶ 4,247:
 
=={{header|Peloton}}==
<langsyntaxhighlight lang="sgml"><@ SAI>
<@ ITEFORLI3>2121|2008|
<@ LETVARCAP>Christmas Day|25-Dec-<@ SAYVALFOR>...</@></@>
Line 3,554 ⟶ 4,255:
</@>
</@>
</@></langsyntaxhighlight>
 
English dialect variable-length space-padded opcodes
<langsyntaxhighlight lang="html"><# suppressimplicitoutput>
<# iterate foriteration literalstring3>2121|2008|
<# let variable capture>Christmas Day|25-Dec-<# say value foriteration>...</#></#>
Line 3,566 ⟶ 4,267:
</#>
</#></langsyntaxhighlight>
 
{{out}}
Line 3,589 ⟶ 4,290:
=={{header|Perl}}==
 
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use Time::Local;
Line 3,604 ⟶ 4,305:
}
 
exit 0;</langsyntaxhighlight>
 
{{out}}
Line 3,619 ⟶ 4,320:
 
Using the DateTime module from CPAN:
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 3,636 ⟶ 4,337:
}
 
exit 0;</langsyntaxhighlight>
or shorter:
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 3,648 ⟶ 4,349:
}
 
exit 0;</langsyntaxhighlight>
{{out}}
<pre>
Line 3,671 ⟶ 4,372:
 
Alternatively in one line using grep (read from right to left):
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 3,678 ⟶ 4,379:
print join " ", grep { DateTime->new(year => $_, month => 12, day => 25)->day_of_week == 7 } (2008 .. 2121);
 
0;</langsyntaxhighlight>
{{out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
Line 3,684 ⟶ 4,385:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Day_of_the_week.exw</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #0000FF;">}</span>
Line 3,693 ⟶ 4,394:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?<span style="color: #000000;">res
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 3,701 ⟶ 4,402:
=={{header|PHP}}==
 
<langsyntaxhighlight lang="php"><?php
for($i=2008; $i<2121; $i++)
{
Line 3,710 ⟶ 4,411:
}
}
?></langsyntaxhighlight>
 
{{out}}
Line 3,734 ⟶ 4,435:
 
=={{header|Picat}}==
<langsyntaxhighlight Picatlang="picat">go =>
L = [Year : Year in 2008..2121, dow(Year, 12, 25) == 0],
println(L),
Line 3,747 ⟶ 4,448:
end,
R = (Y + Y // 4 - Y // 100 + Y // 400 + T[M] + D) mod 7.
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,754 ⟶ 4,455:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(for (Y 2008 (>= 2121 Y) (inc Y))
(when (= "Sunday" (day (date Y 12 25)))
(printsp Y) ) )</langsyntaxhighlight>
{{out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
=={{header|Pike}}==
<langsyntaxhighlight Pikelang="pike">filter(Calendar.Year(2008)->range(Calendar.Year(2121))->years()->month(12)->day(25), lambda(object day){ return day->week_day()==7; })->year()->format_nice();</langsyntaxhighlight>
{{out}}
<pre>
Line 3,783 ⟶ 4,484:
"2118"
})
</pre>
 
=={{header|PL/0}}==
{{trans|GW-BASIC}}
<syntaxhighlight lang="pascal">
var year, month, day, dayofweek;
 
procedure calcdayofweek;
begin
if month < 3 then
begin
year := year - 1;
month := month + 12
end;
dayofweek := year + year / 4 - year / 100 + year / 400;
dayofweek := dayofweek + day + (153 * month + 8) / 5;
dayofweek := dayofweek - (dayofweek / 7) * 7
end;
 
begin
month := 12; day := 25;
year := 2007;
while year <= 2122 do
begin
call calcdayofweek;
if dayofweek = 0 then ! year;
year := year + 1
end
end.
</syntaxhighlight>
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
declare i picture '9999';
do i = 2008 to 2121;
Line 3,792 ⟶ 4,542:
put skip list ('Christmas day ' || i || ' is a Sunday');
end;
</syntaxhighlight>
</lang>
 
==={{header|PL/I-80}}===
<langsyntaxhighlight PLlang="pl/Ii">/* Test of PL/I-80 routine to determine day of the week */
 
sunday_christmas:
Line 3,837 ⟶ 4,587:
 
end sunday_christmas;
</syntaxhighlight>
</lang>
{{out}}
<pre>Christmas will fall on Sunday in these years:
Line 3,857 ⟶ 4,607:
2112
2118
</pre>
 
=={{header|PL/M}}==
{{Trans|ALGOL W}}which is{{Trans|Fortran}}
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<syntaxhighlight lang="plm">
100H: /* FIND YEARS WHERE CHRISTMAS DAY FALLS ON A SUNDAY */
 
/* CP/M BDOS SYSTEM CALL AND I/O ROUTINES */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
 
/* TASK */
 
/* RETURNS THE DAY OF THE WEEK CORRESPONDING To D/M/Y */
DAY$OF$WEEK: PROCEDURE( D, M, Y )BYTE;
DECLARE ( D, M, Y ) ADDRESS;
DECLARE ( J, K, MM, YY ) ADDRESS;
MM = M;
YY = Y;
IF MM <= 2 THEN DO;
MM = MM + 12;
YY = YY - 1;
END;
J = YY / 100;
K = YY MOD 100;
RETURN ( D + ( ( MM + 1 ) * 26 ) / 10 + K + K / 4 + J / 4 + 5 * J )
MOD 7;
END DAY$OF$WEEK ;
 
DECLARE ( YEAR, MONTH, DAY, COUNT ) ADDRESS;
CALL PR$STRING( .'25TH OF DECEMBER IS A SUNDAY IN$' );CALL PR$NL;
COUNT = 0;
DO YEAR = 2008 TO 2121;
DAY = DAY$OF$WEEK( 25, 12, YEAR );
IF DAY = 1 THEN DO;
CALL PR$CHAR( ' ' );CALL PR$NUMBER( YEAR );
IF ( COUNT := COUNT + 1 ) MOD 10= 0 THEN CALL PR$NL;
END;
END;
 
EOF
</syntaxhighlight>
{{out}}
<pre>
25TH OF DECEMBER IS A SUNDAY IN
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072
2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">2008..2121 | Where-Object { (Get-Date $_-12-25).DayOfWeek -eq "Sunday" }</langsyntaxhighlight>
 
===Find Christmas holiday for any day and/or year===
<syntaxhighlight lang="powershell">
<lang PowerShell>
function Get-ChristmasHoliday
{
Line 3,898 ⟶ 4,710:
}
}
</syntaxhighlight>
</lang>
Satisfy the task requirement:
<syntaxhighlight lang="powershell">
<lang PowerShell>
2008..2121 | Get-ChristmasHoliday | where DayOfWeek -match Su
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,926 ⟶ 4,738:
</pre>
Get days off for a random year:
<syntaxhighlight lang="powershell">
<lang PowerShell>
Get-ChristmasHoliday -Year (2008..2121 | Get-Random)
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,936 ⟶ 4,748:
</pre>
Get days off for the current year using the '''Year''' property returned by <code>Get-Date</code>:
<syntaxhighlight lang="powershell">
<lang PowerShell>
(Get-Date | Get-ChristmasHoliday).DaysOff
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,948 ⟶ 4,760:
</pre>
Get days off for the current year as <code>[DateTime]</code> objects:
<syntaxhighlight lang="powershell">
<lang PowerShell>
(Get-Date | Get-ChristmasHoliday).DaysOff | Get-Date
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,962 ⟶ 4,774:
=={{header|Prolog}}==
Works with SWI-Prolog;
<langsyntaxhighlight Prologlang="prolog">main() :-
christmas_days_falling_on_sunday(2011, 2121, SundayList),
writeln(SundayList).
Line 3,974 ⟶ 4,786:
day_of_the_week(Date, DayOfTheWeek),
DayOfTheWeek == 7.
</syntaxhighlight>
</lang>
{{out}}
<pre>?- main.
[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118]
true.</pre>
 
=={{header|PureBasic}}==
PureBasic's internal Date() is limited between 1970-01-01 00:00:00 and 2038-01-19 03:14:07
<lang PureBasic>For i=2008 To 2037
If DayOfWeek(Date(i,12,25,0,0,0))=0
PrintN(Str(i))
EndIf
Next</lang>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">from calendar import weekday, SUNDAY
 
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]</langsyntaxhighlight>
{{out}}
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
Line 4,000 ⟶ 4,804:
Or, in terms of datetime:
{{Works with|Python|3.7}}
<langsyntaxhighlight lang="python">'''Days of the week'''
 
from datetime import date
Line 4,070 ⟶ 4,874:
# MAIN --
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>Years between 2008 and 2121 with 25 Dec on a Sunday:
Line 4,098 ⟶ 4,902:
Using Tomohiko Sakamoto's algorithm.
 
<langsyntaxhighlight Quackerylang="quackery"> [ over 3 < if [ 1 - ]
dup 4 / over +
over 100 / -
Line 4,111 ⟶ 4,915:
2121 1+ 2008 - times
[ 25 12 i^ 2008 + dayofweek
0 = if [ i^ 2008 + echo sp ] ] </langsyntaxhighlight>
 
{{out}}
Line 4,119 ⟶ 4,923:
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">years <- 2008:2121
xmas <- as.POSIXlt(paste0(years, '/12/25'))
years[xmas$wday==0]
Line 4,139 ⟶ 4,943:
 
# Under MS Windows, write instead
Sys.setlocale("LC_ALL", "English")</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
 
Line 4,153 ⟶ 4,957:
(for ([y (in-range 2008 2121)] #:when (xmas-on-sunday? y))
(displayln y))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 4,162 ⟶ 4,966:
As Perl 5, except <code>DateTime</code> is built-in, so you don't need to download a module of that name:
 
<syntaxhighlight lang="raku" perl6line>say join ' ', grep { Date.new($_, 12, 25).day-of-week == 7 }, 2008 .. 2121;</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Yuletide Holiday"
URL: http://rosettacode.org/wiki/Yuletide_Holiday
Line 4,173 ⟶ 4,977:
d: to-date reduce [y 12 25]
if 7 = d/weekday [prin [y ""]]
]</langsyntaxhighlight>
 
{{out}}
Line 4,179 ⟶ 4,983:
 
=={{header|Red}}==
<langsyntaxhighlight Redlang="red">Red []
repeat yy 114 [
d: to-date reduce [25 12 (2007 + yy )]
Line 4,194 ⟶ 4,998:
d/year: d/year + 1
]
</syntaxhighlight>
</lang>
{{out}}<pre>25-Dec-2011
25-Dec-2016
Line 4,236 ⟶ 5,040:
===using DATE weekday===
The extended &nbsp; DATE &nbsp; parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
<langsyntaxhighlight lang="rexx"> do year=2008 to 2121
if date('w', year"1225", 's') == 'Sunday' then say year
end /*year*/</langsyntaxhighlight>
{{out|output}}
<pre>
Line 4,262 ⟶ 5,066:
===using DATE base===
The extended DATE parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
<langsyntaxhighlight lang="rexx"> do year=2008 to 2121
if date('b', year"1225", 's') // 7 == 6 then say year
end /*year*/</langsyntaxhighlight>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br>
 
Line 4,275 ⟶ 5,079:
 
Language note: &nbsp; the DATE &nbsp; built-in function always returns the day-of-week in English, no matter what the native language is in effect.
<langsyntaxhighlight lang="rexx">/*REXX program displays in which years 12/25 (December 25th) falls on a Sunday. */
parse arg start finish . /*get the START and FINISH years. */
if start=='' | start=="," then start=2008 /*Not specified? Then use the default.*/
Line 4,290 ⟶ 5,094:
say 'December 25th,' y "falls on a Sunday."
end /*y*/
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 4,314 ⟶ 5,118:
===old school DOW ===
This &nbsp; DOW &nbsp; (day-of-week) &nbsp; version will work with any version of a REXX interpreter.
<langsyntaxhighlight lang="rexx">/*REXX program (old school) displays in which years 12/25 (Dec. 25th) falls on a Sunday.*/
parse arg start finish . /*get the START and FINISH years. */
if start=='' | start=="," then start=2008 /*Not specified? Then use the default.*/
Line 4,326 ⟶ 5,130:
dow: procedure; parse arg m,d,y; if m<3 then do; m= m+12; y= y-1; end
yL= left(y, 2); yr= right(y, 2); w= (d + (m+1)*26%10 +yr +yr%4 +yL%4 +5*yL) //7
if w==0 then w= 7; return w /*Sunday=1, Monday=2, ··· Saturday=7*/</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 4,349 ⟶ 5,153:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
for n = 2008 to 2121
if n < 2100 leap = n - 1900 else leap = n - 1904 ok
Line 4,355 ⟶ 5,159:
if m = 4 see "25 Dec " + n + nl ok
next
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
Early RPL versions do not have any date library, so a specific instruction implement Zeller's congruence with a stack-oriented algorithm.
{{works with|HP|28}}
≪ '''IF''' OVER 2 ≤ '''THEN''' 1 - SWAP 12 + SWAP '''END'''
100 MOD LAST / FLOOR
DUP 4 / FLOOR SWAP DUP + - SWAP DUP 4 / FLOOR + +
SWAP 1 + 13 * 5 / FLOOR + +
7 MOD 5 + 7 MOD 1 +
≫ '<span style="color:blue">WKDAY</span>' STO
In 1990, RPL gained some basic functions for calculating the date, but nothing for directly obtaining the day of the week.
{{works with|HP|48}}
≪ { "MON" TUE" "WED" "THU" "FRI" "SAT" "SUN" }
SWAP 0 TSTR 1 3 SUB POS
≫ '<span style="color:blue">WKDAY</span>' STO <span style="color:grey">@ ( dd.mmyyyy → 1..7 )</span>
 
≪ { } 2008 2121 '''FOR''' year
'''IF''' 25 12 year <span style="color:blue">WKDAY</span> 7 == '''THEN''' year + '''END NEXT'''
≫ EVAL
{{out}}
<pre>
1: { 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require 'date'
 
(2008..2121).each {|year| puts "25 Dec #{year}" if Date.new(year, 12, 25).sunday? }</langsyntaxhighlight>
{{out}}
<pre>
Line 4,383 ⟶ 5,210:
 
Or using the Time class
<langsyntaxhighlight lang="ruby">(2008..2121).each {|year| puts "25 Dec #{year}" if Time.local(year, 12, 25).sunday?}</langsyntaxhighlight>
{{output}}
<pre>
Line 4,403 ⟶ 5,230:
25 Dec 2112
25 Dec 2118
</pre>
 
(Note: The Time class could not handle dates beyond 2038 prior to Ruby 1.9.2.[https://www.ruby-lang.org/en/news/2010/08/18/ruby-1-9.2-released/])
 
=={{header|Run BASIC}}==
<lang runbasic>for year = 2008 to 2121
if val(date$("12-25-";year)) mod 7 = 5 then print "For ";year;"xmas is Sunday"
next year</lang><pre>
For 2011 xmas is Sunday
For 2016 xmas is Sunday
For 2022 xmas is Sunday
For 2033 xmas is Sunday
For 2039 xmas is Sunday
For 2044 xmas is Sunday
For 2050 xmas is Sunday
For 2061 xmas is Sunday
For 2067 xmas is Sunday
For 2072 xmas is Sunday
For 2078 xmas is Sunday
For 2089 xmas is Sunday
For 2095 xmas is Sunday
For 2101 xmas is Sunday
For 2107 xmas is Sunday
For 2112 xmas is Sunday
For 2118 xmas is Sunday
</pre>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">extern crate chrono;
 
use chrono::prelude::*;
Line 4,438 ⟶ 5,240:
let years = (2008..2121).filter(|&y| Local.ymd(y, 12, 25).weekday() == Weekday::Sun).collect::<Vec<i32>>();
println!("Years = {:?}", years);
}</langsyntaxhighlight>
 
Output:
<pre>Years = [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]
</pre>
 
=={{header|S-BASIC}}==
<lang BASIC>
$constant SUNDAY = 0
 
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
 
rem - main program
var year = integer
print "Christmas will fall on a Sunday in"
for year=2008 to 2121
if dayofweek(12,25,year) = SUNDAY then
print year
next year
end
</lang>
{{out}}
<pre>Christmas will fall on a Sunday in
2011
2016
2011
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|SAS}}==
<langsyntaxhighlight lang="sas">data _null_;
do y=2008 to 2121;
a=mdy(12,25,y);
Line 4,509 ⟶ 5,255:
 
/* 2011 2016 2022 2033 2039 2044 2050 2061 2067
2072 2078 2089 2095 2101 2107 2112 2118 */</langsyntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
===JDK (discouraged) ===
<langsyntaxhighlight lang="scala">import java.util.{ Calendar, GregorianCalendar }
import Calendar.{ DAY_OF_WEEK, DECEMBER, SUNDAY }
 
Line 4,531 ⟶ 5,277:
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</langsyntaxhighlight>
===JDK >= 8 (recommended)===
====Naive programming====
<langsyntaxhighlight lang="scala">import java.time.{ DayOfWeek, LocalDate }
 
object DayOfTheWeek1 extends App {
Line 4,546 ⟶ 5,292:
s"${yuletide.count(p => true)} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</langsyntaxhighlight>
====Idiomatic programming====
<langsyntaxhighlight lang="scala">import java.time.{ DayOfWeek, LocalDate }
 
object DayOfTheWeek1 extends App {
Line 4,563 ⟶ 5,309:
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</langsyntaxhighlight>
====Tail recursion====
<langsyntaxhighlight lang="scala">import java.time.{ DayOfWeek, LocalDate }
import scala.annotation.tailrec
 
Line 4,589 ⟶ 5,335:
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</langsyntaxhighlight>
{{out | Output of all solutions }}
<pre>Years between 2008 and 2121 including when Christmas is observed on Sunday:
Line 4,595 ⟶ 5,341:
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(define (day-of-week year month day)
(if (< month 3)
(begin (set! month (+ month 12)) (set! year (- year 1))))
Line 4,613 ⟶ 5,359:
 
(task)
; (2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</langsyntaxhighlight>
 
=={{header|Seed7}}==
Line 4,619 ⟶ 5,365:
the function [http://seed7.sourceforge.net/libraries/time.htm#dayOfWeek%28in_time%29 dayOfWeek],
which returns 1 for monday, 2 for tuesday, and so on up to 7 for sunday.
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "time.s7i";
 
Line 4,631 ⟶ 5,377:
end if;
end for;
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 4,654 ⟶ 5,400:
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang="sensetalk">// In what years between 2008 and 2121 will the 25th of December be a Sunday?
 
repeat with year = 2008 to 2121
Line 4,661 ⟶ 5,407:
put "Christmas in " & year & " falls on a Sunday"
end if
end repeat</langsyntaxhighlight>
{{out}}
<pre>
Line 4,685 ⟶ 5,431:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">require('Time::Local')
 
for year in (2008 .. 2121) {
Line 4,693 ⟶ 5,439:
say "25 Dec #{year} is Sunday"
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,714 ⟶ 5,460:
25 Dec 2118 is Sunday
</pre>
 
=={{header|Simula}}==
{{trans|Sinclair ZX81 BASIC}}
<langsyntaxhighlight lang="simula">BEGIN
INTEGER M,D,Y;
M := 12;
Line 4,732 ⟶ 5,479:
END;
END;
END.</langsyntaxhighlight>
{{out}}
<pre>2011
Line 4,753 ⟶ 5,500:
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">2008 to: 2121 do: [ :year | |date|
date := Date newDay: 25 monthIndex: 12 year: year.
date dayName = #Sunday
ifTrue: [ date displayNl ]
]</langsyntaxhighlight>
 
{{out}}
Line 4,778 ⟶ 5,525:
25-Dec-2118</pre>
 
=={{header|SQLSparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "yuletide" );
pragma annotate( description, "A company decides that whenever Xmas falls on a Sunday they will give their" );
pragma annotate( description, "workers all extra paid holidays so that, together with any public holidays," );
pragma annotate( description, "workers will not have to work the following week (between the 25th of" );
pragma annotate( description, "December and the first of January)." );
pragma annotate( description, "");
pragma annotate( description, "In what years between 2008 and 2121 will the 25th of December be a Sunday?" );
pragma annotate( description, "");
pragma annotate( description, "Using any standard date handling libraries of your programming language;" );
pragma annotate( description, "compare the dates calculated with the output of other languages to discover" );
pragma annotate( description, "any anomalies in the handling of dates which may be due to, for example," );
pragma annotate( description, "overflow in types used to represent dates/times similar to y2k type" );
pragma annotate( description, "problems. ");
pragma annotate( see_also, "http://rosettacode.org/wiki/Day_of_the_week" );
pragma annotate( author, "Ken O. Burtch ");
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure yuletide is
begin
for Year in 2008..2121 loop
if calendar.day_of_week ( calendar.time_of (Year, 12, 25, 0)) = 1 then
put_line( "Christmas " & strings.image( Year ) & " is on a Sunday" );
end if;
end loop;
end yuletide;</syntaxhighlight>
 
=={{header|SQL}}==
===Oracle===
SQL has good support for date functions; care must be taken with NLS settings (globalization support), in the code below the date format language is passed in as an argument to the relevant function. (Or, see a variation that does not depend on language settings, after the output shown below.)
 
<langsyntaxhighlight lang="sql">select extract(year from dt) as year_with_xmas_on_sunday
from (
select add_months(date '2008-12-25', 12 * (level - 1)) as dt
Line 4,790 ⟶ 5,568:
where to_char(dt, 'Dy', 'nls_date_language=English') = 'Sun'
order by 1
;</langsyntaxhighlight>
 
 
Line 4,819 ⟶ 5,597:
Alternatively, the WHERE clause can be written in a way that avoids the complication of language settings. The (overloaded) TRUNC function, as applied to dates, takes a second argument indicating "to what" we must truncate. One option is 'iw' for "ISO week"; this truncates to the most recent Monday (the beginning of the ISO standard week, which is Monday through Sunday by definition). Like so (replace in the query above):
 
 
<lang sql>where dt - trunc(dt, 'iw') = 6</lang>
<syntaxhighlight lang="sql">where dt - trunc(dt, 'iw') = 6</syntaxhighlight>
 
===SQLite3===
<syntaxhighlight lang="sql">WITH RECURSIVE cte AS (
SELECT DATE('2008-12-25', '+'||(12*0)||' months') as dt, 1 AS level
UNION ALL
SELECT DATE('2008-12-25', '+'||(12*level)||' months') as dt, c.level + 1
FROM cte c
WHERE c.level <= 2121 - 2008 + 1
)
SELECT strftime('%Y', dt)
FROM cte
where strftime('%w', dt) = '0';
</syntaxhighlight>
 
===PostgreSQL===
<syntaxhighlight lang="sql"> WITH RECURSIVE cte AS (
SELECT date '2008-12-25' + interval '12 month' * 0 as dt, 1 AS level
UNION ALL
SELECT date '2008-12-25' + interval '12 month' * level as dt, c.level + 1
FROM cte c
WHERE c.level <= 2121 - 2008 + 1
)
SELECT dt
FROM cte
where to_char(dt, 'Dy') = 'Sun';
</syntaxhighlight>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">(* Call: yearsOfSundayXmas(2008, 2121) *)
fun yearsOfSundayXmas(fromYear, toYear) =
if fromYear>toYear then
Line 4,840 ⟶ 5,645:
else
yearsOfSundayXmas(fromYear+1, toYear)
end;</langsyntaxhighlight>
 
{{out}}
Line 4,865 ⟶ 5,670:
 
The [https://www.stata.com/help.cgi?dow() <code>dow()</code>] function returns the day of week, where sunday is zero and saturday is 6.
<langsyntaxhighlight lang="stata">clear
sca n=2121-2008+1
set obs `=n'
Line 4,891 ⟶ 5,696:
| 2112 |
| 2118 |
+------+</langsyntaxhighlight>
 
=== Mata ===
 
<langsyntaxhighlight lang="mata">year=2008::2121
select(year,dow(mdy(12,25,year)):==0)</langsyntaxhighlight>
 
=={{header|Suneido}}==
<langsyntaxhighlight Suneidolang="suneido">year = 2008
while (year <= 2121)
{
Line 4,905 ⟶ 5,710:
Print(year)
++year
}</langsyntaxhighlight>
{{out}}
<pre>2011
Line 4,926 ⟶ 5,731:
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">import Cocoa
 
var year=2008
let formatter=NSDateFormatterDateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
 
let gregorian:NSCalendar! = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorianNSCalendar.Identifier.gregorian)
while (year<2122){
var date:NSDate!=formatter.dateFromStringdate(from: String(year)+"-12-25") as NSDate?
var components=gregorian.components(NSCalendarUnitNSCalendar.CalendarUnitWeekdayUnit.weekday, fromDatefrom: date as Date)
var dayOfWeek:NSInteger=components.weekday!
if(dayOfWeek==1){
printlnprint(year)
}
year++=1
}
}</lang>
</syntaxhighlight>
{{out}}
<pre>2011
Line 4,963 ⟶ 5,769:
=={{header|Tcl}}==
{{works with|Tcl|8.5}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
 
for {set y 2008} {$y <= 2121} {incr y} {
Line 4,969 ⟶ 5,775:
puts "xmas $y is a sunday"
}
}</langsyntaxhighlight>
{{out}}
<pre>xmas 2011 is a sunday
Line 4,988 ⟶ 5,794:
xmas 2112 is a sunday
xmas 2118 is a sunday</pre>
 
=={{header|TI-83 BASIC}}==
'''Works with''' TI-84+/SE only
<lang ti83b>
:For(A,2008,2121
:If dayofWk(A,12,25)=1
:Disp A
:End
</lang>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
Done</pre>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
PRINT "25th of December will be a Sunday in the following years: "
Line 5,025 ⟶ 5,803:
IF (dayofweek==7) PRINT year
ENDLOOP
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 5,050 ⟶ 5,828:
== {{header|TypeScript}} ==
{{trans|Minimal BASIC}}
<langsyntaxhighlight lang="javascript">
// Find years with Sunday Christmas
var f = 2008;
Line 5,061 ⟶ 5,839:
}
process.stdout.write("\n");
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 5,075 ⟶ 5,853:
 
{{works with|bash}}
<langsyntaxhighlight lang="bash">#! /bin/bash
 
for (( i=2008; i<=2121; ++i ))
Line 5,082 ⟶ 5,860:
done |grep Sun
 
exit 0</langsyntaxhighlight>
 
The first lines of output (from a GNU/Linux system with 32bit time_t, date version 6.9) are
 
<langsyntaxhighlight lang="bash">Sun Dec 25 00:00:00 CET 2011
Sun Dec 25 00:00:00 CET 2016
Sun Dec 25 00:00:00 CET 2022
Sun Dec 25 00:00:00 CET 2033
date: invalid date `2038-12-25'</langsyntaxhighlight>
 
I.e., starting from year 2038, the <tt>date</tt> command (which uses the glibc library, at least on GNU systems), is not able to recognise the date as a valid one!
Line 5,096 ⟶ 5,874:
''Different machine/OS version (64 bit time_t):''
This is the same command run on RedHat Linux.
<langsyntaxhighlight lang="bash">bash-3.00$ date --version
date (coreutils) 5.2.1
Written by David MacKenzie.
Line 5,123 ⟶ 5,901:
Sun Dec 25 00:00:00 GMT 2112
Sun Dec 25 00:00:00 GMT 2118
bash-3.00$</langsyntaxhighlight>
 
===With GNU date and GNU seq ({{header|UnixPipes}})===
Like the previous solution, this solution uses date -d, which seems to be a [[GNU]] extension. Output is same as previous solution.
 
<langsyntaxhighlight lang="bash">seq 2008 2121 | xargs -IYEAR -n 1 date +%c -d 'Dec 25 YEAR' | grep Sun</langsyntaxhighlight>
 
===With Unix cal===
Line 5,146 ⟶ 5,924:
 
{{works with|Bourne Shell}}
<langsyntaxhighlight lang="bash">y=2008
while test $y -lt 2122; do
cal 12 $y | tail +3 | cut -c1-2 | grep -Fq 25 && echo 25 Dec $y
y=`expr $y + 1`
done</langsyntaxhighlight>
 
Running this script with [[OpenBSD]], the output is identical to the C# program. OpenBSD ''cal'' accepts any year from 1 to 9999, so 2008 to 2122 is well within range.
 
===With zsh===
<langsyntaxhighlight lang="bash">zmodload zsh/datetime
for (( year = 2010; year <= 2121; year++ ));
if [[ $(strftime '%A' $(strftime -r '%F' $year-12-25)) == Sunday ]] print $year</langsyntaxhighlight>
 
If the system has 32-bit time, this script will malfunction for years >= 2038; it will print no year from 2038 to 2121 (unless today is Sunday, then it prints every year from 2038 to 2121). This happens because ''strftime -r '%F' $year-12-25'' yields -1 for an out-of-range date, and ''strftime '%A' -1'' yields name of today.
Line 5,174 ⟶ 5,952:
date with the weekday included. The output is then filtered for Sundays.
 
<langsyntaxhighlight Ursalalang="ursala">#import std
#import nat
#import stt
Line 5,182 ⟶ 5,960:
#show+
 
sunday_years = ~&zS sep` * =]'Sun'*~ christmases</langsyntaxhighlight>
{{out}}
<pre>2011
Line 5,201 ⟶ 5,979:
2112
2118</pre>
 
=={{header|VBA}}==
<lang vb>Option Explicit
 
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
 
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function</lang>
 
{{Out}}
<pre>Xmas will be a Sunday in : 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118</pre>
 
=={{header|VBScript}}==
<lang vb>For year = 2008 To 2121
If Weekday(DateSerial(year, 12, 25)) = 1 Then
WScript.Echo year
End If
Next</lang>
 
{{Out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">Buf_Switch(Buf_Free)
for (#3 = 2008; #3 < 2122; #3++) {
Reg_Set(10, "12/25/")
Line 5,256 ⟶ 5,988:
Num_Ins(#3, NOCR)
}
}</langsyntaxhighlight>
 
{{out}}
Line 5,264 ⟶ 5,996:
 
=={{header|Visual Objects}}==
<langsyntaxhighlight lang="visualfoxpro">
local i as dword
Line 5,272 ⟶ 6,004:
endif
next i
</syntaxhighlight>
</lang>
 
{{out}}
Line 5,279 ⟶ 6,011:
</pre>
 
=={{header|V (Vlang)}}==
Updated for Vlang version 0.2.2
<langsyntaxhighlight lang="go">import time
 
fn main() {
Line 5,290 ⟶ 6,022:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 5,316 ⟶ 6,048:
{{Trans|ALGOL W}}...which is {{Trans|Fortran}}
VTL-2 does not have operator precedence - all expressions are evaluated left-to-right, except for expressions nested in parenthesis, hence the expression at line 1090 differs from that in the Algol W sample.
<langsyntaxhighlight VTL2lang="vtl2">1000 #=2000
1010 R=!
1020 N=M
Line 5,337 ⟶ 6,069:
2080 Y=Y+1
2090 #=Y<2121*2040
2100 ?=""</langsyntaxhighlight>
{{out}}
<pre>
Line 5,344 ⟶ 6,076:
 
=={{header|Wortel}}==
<langsyntaxhighlight lang="wortel">!-&y = 0 `.getDay. @new Date[y 11 25] @range[2008 2121]</langsyntaxhighlight>
Returns: <pre>[2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118]</pre>
 
=={{header|Wren}}==
{{libheader|Wren-date}}
<langsyntaxhighlight ecmascriptlang="wren">import "./date" for Date
 
System.print("Years between 2008 and 2121 when 25th December falls on Sunday:")
for (year in 2008..2121) {
if (Date.new(year, 12, 25).dayOfWeek == 7) System.print(year)
}</langsyntaxhighlight>
 
{{out}}
Line 5,383 ⟶ 6,115:
the Gregorian calendar, from 1583 onward. It's based on Zeller's Congruence.
 
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
 
func WeekDay(Year, Month, Day); \Return day of week (0=Sat 1=Sun..6=Fri)
Line 5,396 ⟶ 6,128:
if WeekDay(Year, 12, 25) = 1 then \25th of December is a Sunday
[IntOut(0, Year); CrLf(0)];
]</langsyntaxhighlight>
 
{{out}}
Line 5,418 ⟶ 6,150:
2118
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<lang Yabasic>sub wd(m, d, y)
If m < 3 Then // If m = 1 Or m = 2 Then
m = m + 12
y = y - 1
End If
Return mod((y + int(y / 4) - int(y / 100) + int(y / 400) + d + int((153 * m + 8) / 5)), 7)
End sub
// ------=< MAIN >=------
For yr = 2008 To 2121
If wd(12, 25, yr) = 0 Then
Print "Dec 25 ", yr
EndIf
Next</lang>
 
=={{header|zkl}}==
ISO dates, monday is 1, sunday is 7
<langsyntaxhighlight lang="zkl">var [const] D=Time.Date;
foreach y in ([2008..2121]){
if (D.Sunday==D.weekDay(y,12,25)) println(y)
}</langsyntaxhighlight>
Or, in a more functional manner:
<langsyntaxhighlight lang="zkl">var [const] D=Time.Date;
[2008..2121].filter(fcn(y){ D.Sunday==D.weekDay(y,12,25) }).println()</langsyntaxhighlight>
{{out}}
<pre>
Line 5,468 ⟶ 6,182:
 
=={{header|zonnon}}==
<langsyntaxhighlight lang="zonnon">
module Main;
(*Access to Mono System package *)
Line 5,480 ⟶ 6,194:
System.Console.WriteLine(now.DayOfWeek);
end Main.
</syntaxhighlight>
</lang>
{{Out}}
<pre>
2017-12-05 :Tuesday
</pre>
 
=={{header|ZX Spectrum Basic}}==
{{trans|BASIC}}
<lang zxbasic>10 CLS
20 FOR y=2008 TO 2121
30 LET year=y: LET m=12: LET d=25: GO SUB 1000
40 IF wd=0 THEN PRINT d;" ";m;" ";y
50 NEXT y
60 STOP
1000 REM week day
1010 IF m=1 OR m=2 THEN LET m=m+12: LET year=year-1
1020 LET wd=FN m(year+INT (year/4)-INT (year/100)+INT (year/400)+d+INT ((153*m+8)/5),7)
1030 RETURN
1100 DEF FN m(a,b)=a-INT (a/b)*b</lang>
9,476

edits