Day of the week: Difference between revisions

Added MiniScript
(→‎{{header|Python}}: Updated output)
(Added MiniScript)
 
(152 intermediate revisions by 56 users not shown)
Line 13:
compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to   [[wp:Y2k#See_also|y2k]]   type problems.
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">print((2008..2121).filter(y -> Time(y, 12, 25).strftime(‘%w’) == ‘0’))</syntaxhighlight>
{{out}}
<pre>
[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]
</pre>
 
=={{header|360 Assembly}}==
{{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 59 ⟶ 66:
PG DS CL12 buffer
YREGS
END DOW</langsyntaxhighlight>
{{out}}
<pre style="height:16ex"> 2011
Line 80 ⟶ 87:
 
=={{header|ABAP}}==
<langsyntaxhighlight ABAPlang="abap">report zday_of_week
data: lv_start type i value 2007,
lv_n type i value 114,
Line 104 ⟶ 111:
endif.
enddo.
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 129 ⟶ 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 159 ⟶ 166:
OD
RETURN
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 181 ⟶ 188:
2118
</pre>
 
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
Line 194 ⟶ 200:
end if;
end loop;
end Yuletide;</langsyntaxhighlight>
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 222 ⟶ 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 244 ⟶ 250:
new line(stand out)
)
</syntaxhighlight>
</lang>
{{out}}
<pre>
December 25th is a Sunday in: 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|ALGOL W}}==
{{Trans|Fortran}}
<syntaxhighlight lang="algolw">begin % find years where Christmas day falls on a Sunday %
integer procedure Day_of_week ( integer value d, m, y );
begin
integer j, k, mm, yy;
mm := m;
yy := y;
if mm <= 2 then begin
mm := mm + 12;
yy := yy - 1;
end if_m_le_2;
j := yy div 100;
k := yy rem 100;
(d + ( ( mm + 1 ) * 26 ) div 10 + k + k div 4 + j div 4 + 5 * j ) rem 7
end Day_of_week;
write( "25th of December is a Sunday in" );
for year := 2008 until 2121 do begin
integer day;
day := Day_of_week( 25, 12, year );
if day = 1 then writeon( I_W := 5, S_W := 0, year );
end for_year
end.</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|ALGOL-M}}==
<syntaxhighlight lang="algol">
BEGIN
 
% CALCULATE P MOD Q %
INTEGER FUNCTION MOD(P, Q);
INTEGER P, Q;
BEGIN
MOD := P - Q * (P / Q);
END;
 
COMMENT
RETURN DAY OF WEEK (SUN=0, MON=1, ETC.) FOR A GIVEN
GREGORIAN CALENDAR DATE USING ZELLER'S CONGRUENCE;
INTEGER FUNCTION DAYOFWEEK(MO, DA, YR);
INTEGER MO, DA, YR;
BEGIN
INTEGER Y, C, Z;
IF MO < 3 THEN
BEGIN
MO := MO + 10;
YR := YR - 1;
END
ELSE MO := MO - 2;
Y := MOD(YR, 100);
C := YR / 100;
Z := (26 * MO - 2) / 10;
Z := Z + DA + Y + (Y / 4) + (C /4) - 2 * C + 777;
DAYOFWEEK := MOD(Z, 7);
END;
 
% MAIN PROGRAM STARTS HERE %
INTEGER YEAR, SUNDAY;
SUNDAY := 0;
WRITE("CHRISTMAS WILL FALL ON A SUNDAY IN THESE YEARS:");
FOR YEAR := 2008 STEP 1 UNTIL 2121 DO
BEGIN
IF DAYOFWEEK(12, 25, YEAR) = SUNDAY THEN
WRITE(YEAR);
END;
 
END
</syntaxhighlight>
{{out}}
<pre>
CHRISTMAS WILL FALL ON A SUNDAY IN THESE YEARS:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
=={{header|APL}}==
<syntaxhighlight 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
⍝ Simplified Zeller function operating on table of dates formatted as 114 rows and 3 columns of (day, month, year)
⍝ 0 = Saturday, 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday
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>
{{out}}
<pre>
result
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">set ChristmasSundays to {}
set Christmas to (current date)
set month of Christmas to December
set day of Christmas to 25
repeat with |year| from 2008 to 2121
set year of Christmas to |year|
if weekday of Christmas is Sunday then set end of ChristmasSundays to |year|
end repeat
ChristmasSundays</langsyntaxhighlight>
 
 
Or, composing generic functions:
<syntaxhighlight lang ="applescript">on run
-- xmasOnSundayxmasIsSunday :: Int -> Bool
on xmasIsSunday(y)
script xmasOnSunday
tell (current on |λ|(ydate)
set {its year, its month, its day, its time} to {y, 12, 25, 0}
tell (current date)
its weekday is Sunday
set {its year, its month, its day, its time} to {y, 12, 25, 0}
end tell
return its weekday is Sunday
end xmasIsSunday
end tell
 
end |λ|
 
end script
-------------------------- TEST ---------------------------
on run
filter(xmasIsSunday, enumFromTo(2008, 2121))
filter(xmasOnSunday, enumFromTo(2008, 2121))
end run
 
 
-- GENERIC FUNCTIONS -------------------------------------- GENERIC FUNCTIONS --------------------
 
-- enumFromTo :: Int -> Int -> [Int]
Line 287 ⟶ 403:
set end of lst to i
end repeat
return lst
else
return {}
end if
end enumFromTo
 
 
-- filter :: (a -> Bool) -> [a] -> [a]
Line 305 ⟶ 422:
end tell
end filter
 
 
-- Lift 2nd class handler function into 1st class script wrapper
Line 316 ⟶ 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 331 ⟶ 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 355 ⟶ 473:
2118
 
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]</syntaxhighlight>
 
{{out}}
 
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 </pre>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">year = 2008
stop = 2121
 
Line 367 ⟶ 495:
year++
}
MsgBox,% out</langsyntaxhighlight>
 
=={{header|AutoIt}}==
<langsyntaxhighlight AutoItlang="autoit">#include <date.au3>
Const $iSunday = 1
For $iYear = 2008 To 2121 Step 1
Line 376 ⟶ 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 389 ⟶ 516:
}
}
</syntaxhighlight>
</lang>
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<b>Works with:</b> FreeBASIC <br>
{{trans|Commodore BASIC}}
This program needs the modulo function because there is a bug in the built in modulo function.
<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:
<lang BASIC>Declare Function modulo(x As Double, y As Double) As Double
REM Sunday = 0, Saturday = 6
Declare Function wd(m As Double, d As Double, y As Double) As Integer
IF Month < 3 THEN
Year = Year - 1
Month = Month + 12
ENDIF
DayOfWeek = Year
YearDiv = Year / 4
DayOfWeek = DayOfWeek + YearDiv
YearDiv = Year / 100
DayOfWeek = DayOfWeek - YearDiv
YearDiv = Year / 400
DayOfWeek = DayOfWeek + YearDiv
DayPlus = 153 * Month
DayPlus = DayPlus + 8
DayPlus = DayPlus / 5
DayOfWeek = DayOfWeek + Day
DayOfWeek = DayOfWeek + DayPlus
DayOfWeek = DayOfWeek MOD 7
RETURN
</syntaxhighlight>
{{out}}
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
==={{header|Atari BASIC}}===
Cls
{{trans|Commodore BASIC}}
Dim yr As Double
<syntaxhighlight lang="basic">100 REM FIND YEARS WITH SUNDAY CHRISTMAS
For yr = 2008 To 2121
110 PRINT CHR$(125);"SUNDAY CHRISTMASES 2008-2121:":PRINT
If wd(12,25,yr) = 1 Then
120 FOR Y=2008 TO 2121
Print "Dec " & 25 & ", " & yr
130 EOY=Y*365+INT(Y/4)-INT(Y/100)+INT(Y/400)
EndIf
140 XMAS=EOY-6
Next
150 DOW=XMAS-7*INT(XMAS/7)
Sleep
160 IF DOW THEN 220
170 PRINT Y;
180 FOUND=FOUND+1
190 IF FOUND<3 THEN PRINT ,:GOTO 220
200 FOUND=0
210 PRINT
220 NEXT Y
230 IF FOUND THEN PRINT</syntaxhighlight>
 
{{Out}}
Function modulo(x As Double, y As Double) As Double
<pre> SUNDAY CHRISTMASES 2008-2121
If y = 0 Then
Return x
Else
Return x - y * Int(x / y)
End If
End Function
 
2011 2016 2022
Function wd(m As Double, d As Double, y As Double) As Integer
2033 2039 2044
If m = 1 Or m = 2 Then
2050 2061 2067
m += 12
2072 2078 2089
y-= 1
2095 2101 2107
End If
2112 2118</pre>
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|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 469 ⟶ 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.
 
<syntaxhighlight 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)
130 REM RATA DIE OF 31 DEC Y (CAN BE TAKEN MODULO 7 TO GET DAY OF WEEK)
140 DEF FNRD(Y) = 365 * Y + INT(Y/4) - INT(Y/100) + INT(Y/400)
150 REM TRUE IF THE GIVEN RD IS A SUNDAY
160 DEF FND7(N) = 0 = FNNM(7)
170 REM TRUE IF CHRISTMAS FALLS ON A SUNDAY IN THE GIVEN YEAR
180 DEF FNXS(Y) = FND7(FNRD(Y) - 6):REM 6 DAYS BEFORE THE END OF THE YEAR
190 REM TRY OUR TARGET YEARS AND OUTPUT THE ONES THAT MATCH
200 Y1 = 2008: Y2 = 2121
210 PRINT CHR$(147);"CHRISTMASES ON SUNDAY";Y1;"-";Y2;CHR$(13)
220 FOR Y=Y1 TO Y2
230 : IF FNXS(Y) THEN PRINT Y,:REM PRINT YEARS IN COLUMNS
240 NEXT Y
250 PRINT</syntaxhighlight>
 
{{Out}}
<pre>CHRISTMASES ON SUNDAY 2008 - 2121:
 
2011 2016 2022 2033
2039 2044 2050 2061
2067 2072 2078 2089
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 494 ⟶ 732:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>Dec 25 2011
Line 513 ⟶ 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 529 ⟶ 815:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>25-12-2011
Line 548 ⟶ 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}}
<syntaxhighlight lang="gwbasic">10 REM Day of the week
20 DEFINT D, M, Y-Z
30 M = 12: D = 25
40 FOR Y = 2007 TO 2122
50 GOSUB 200
60 IF Z = 0 THEN PRINT Y;
70 NEXT Y
80 PRINT
90 END
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 THEN Y = Y - 1: M = M + 12
210 Z = Y + Y \ 4 - Y \ 100 + Y \ 400
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 559 ⟶ 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}}
<syntaxhighlight lang="gwbasic">10 REM Find years with Sunday Christmas
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|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 576 ⟶ 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 595 ⟶ 1,188:
2112
2118</pre>
 
==={{header|TI-83 BASIC}}===
{{Works with|TI-84+/SE}} only
<syntaxhighlight lang="ti83b">
:For(A,2008,2121
:If dayofWk(A,12,25)=1
:Disp A
:End
</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
Done</pre>
 
==={{header|Tiny BASIC}}===
{{works with|TinyBasic}}
<syntaxhighlight lang="basic">10 REM Day of the week
20 LET Y = 2007
30 LET M = 12
40 LET D = 25
50 IF Y = 2122 THEN END
60 LET Y = Y + 1
70 GOSUB 200
80 IF Z = 0 THEN PRINT Y
90 GOTO 50
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 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</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
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}}==
<syntaxhighlight lang="dos">:: Day of the Week task from Rosetta Code
<lang dos>
:: Day of the Week task from Rosetta Code Wiki
:: Batch File Implementation
:: Question: In what years between 2008 and 2121 will the 25th of December be a Sunday?
::
:: Method: Zeller's Rule
:: In what years between 2008 and 2121 will the 25th of December be a Sunday?
::
:: This implementation uses Zeller's Rule...
 
@echo off
rem set month code for December
 
::Set month code for December
set mon=33
rem set day number
 
::Set day number
set day=25
 
for /L %%wy in (2008,1,2121) do (
setlocal enabledelayedexpansion
call :check_day %%w
set /a "a=%%y/100"
set /a "b=%%y-(a*100)"
set /a "weekday=(day+mon+b+(b/4)+(a/4)+(5*a))%%7"
if "!weekday!"=="1" echo(Dec 25, %%y is a Sunday.
endlocal
)
pause>nul
exit /b 0</syntaxhighlight>
 
:check_day
set yr=%1
set /a a=%yr%/100
set /a b=%yr%-(%a%*100)
set /a weekday=(%day%+%mon%+%b%+(%b%/4)+(%a%/4)+(5*%a%))%%7
if %weekday%==1 (
echo Dec 25, %yr% is a Sunday.
)
goto :EOF
</lang>
{{out}}
<pre>Dec 25, 2011 is a Sunday.
<pre>
Dec 25, 2011 is a Sunday.
Dec 25, 2016 is a Sunday.
Dec 25, 2022 is a Sunday.
Line 648 ⟶ 1,415:
Dec 25, 2112 is a Sunday.
Dec 25, 2118 is a Sunday.
Press any key to continue . . .</pre>
</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 684 ⟶ 1,441:
if (w(y, 12, 25) == 0) y
}
quit</langsyntaxhighlight>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let weekday(y, m, d) =
m<3 -> wd((y-1)/100, (y-1) rem 100, m + 10, d),
wd(y/100, y rem 100, m - 2, d)
and wd(c, y, m, d) =
((26*m-2)/10 + d + y + y/4 + c/4 - 2 * c + 777) rem 7
 
let start() be
for year = 2008 to 2121
if weekday(year, 12, 25) = 0
do writef("%N*N", year)</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|Befunge}}==
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 714 ⟶ 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 740 ⟶ 1,529:
& 1+!y:?y
)
& done;</langsyntaxhighlight>
{{out}}
<pre>2011-12-25
Line 763 ⟶ 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 786 ⟶ 1,575:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C++}}==
<lang cpp>#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
 
int main( ) {
using namespace boost::gregorian ;
 
std::cout
<< "Yuletide holidays must be allowed in the following years:\n" ;
for ( int i = 2008 ; i < 2121 ; i++ ) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) ;
if ( d.day_of_week( ) == Sunday ) {
std::cout << i << std::endl ;
}
}
std::cout << "\n" ;
return 0 ;
}</lang>
{{out}}
<pre>
Yuletide holidays must be allowed in the following years:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
class Program
Line 845 ⟶ 1,593:
}
}
}</langsyntaxhighlight>
 
Using LINQ:
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 862 ⟶ 1,610:
foreach (string day in days) Console.WriteLine(day);
}
}</langsyntaxhighlight>Lambda expressions FTW:
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 875 ⟶ 1,623:
.ForEach(ent => Console.WriteLine(ent.ToString("dd MMM yyyy")));
}
}</langsyntaxhighlight>
{{out}}
<pre style="height:20ex;overflow:scroll">25 Dec 2011
Line 894 ⟶ 1,642:
25 Dec 2112
25 Dec 2118</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <chrono>
#include <ranges>
#include <iostream>
 
int main() {
std::cout << "Yuletide holidays must be allowed in the following years:\n";
for (int year : std::views::iota(2008, 2121)
| std::views::filter([](auto year) {
if (std::chrono::weekday{
std::chrono::year{year}/std::chrono::December/25}
== std::chrono::Sunday) {
return true;
}
return false;
})) {
std::cout << year << '\n';
}
}</syntaxhighlight>
{{out}}
<pre>
Yuletide holidays must be allowed in the following years:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Clojure}}==
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}}==
<syntaxhighlight lang="clu">weekday = proc (d: date) returns (int)
y: int := d.year
m: int := d.month
if m<3
then y, m := y-1, m+10
else m := m-2
end
c: int := y/100
y := y//100
z: int := (26*m-2)/10 + d.day + y + y/4 + c/4 - 2*c + 777
return(z//7)
end weekday
 
start_up = proc ()
po: stream := stream$primary_output()
for year: int in int$from_to(2008, 2121) do
if weekday(date$create(25, 12, year, 0, 0, 0))=0 then
stream$putl(po, int$unparse(year))
end
end
end start_up</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|COBOL}}==
Using Date Intrinsic Functions
<syntaxhighlight lang="cobol">
<lang COBOL>
program-id. dec25.
data division.
Line 934 ⟶ 1,766:
.
end program dec25.
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:20ex;overflow:scroll">
Line 958 ⟶ 1,790:
Without Date Intrinsic Functions
 
<syntaxhighlight lang="cobol">
<lang Cobol>
identification division.
program-id. dowtest.
Line 1,027 ⟶ 1,859:
.
end program todow.
</syntaxhighlight>
</lang>
{{out}}
<pre style="height:20ex;overflow:scroll">
Line 1,050 ⟶ 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,077 ⟶ 1,909:
 
=={{header|ColdFusion}}==
<syntaxhighlight lang="coldfusion">
<lang ColdFusion>
<cfloop from = "2008" to = "2121" index = "i">
<cfset myDate = createDate(i, 12, 25) />
Line 1,084 ⟶ 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,093 ⟶ 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,140 ⟶ 1,972:
 
END DayOfWeek.
</syntaxhighlight>
</lang>
Execute: ^Q DayOfWeek.Do 2008 2121~
{{out}}
Line 1,162 ⟶ 1,994:
2118
</pre>
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub weekday(year: uint16, month: uint8, day: uint8): (wd: uint8) is
if month < 3 then
month := month + 10;
year := year - 1;
else
month := month - 2;
end if;
var c := year / 100;
var y := year % 100;
var z := (26 * month as uint16 - 2) / 10;
z := z + day as uint16 + y + (y / 4) + (c / 4) - 2 * c + 777;
wd := (z % 7) as uint8;
end sub;
 
var year: uint16 := 2008;
while year <= 2121 loop
if weekday(year, 12, 25) == 0 then
print_i16(year);
print_nl();
end if;
year := year + 1;
end loop;</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.range, std.algorithm, std.datetime;
 
Line 1,170 ⟶ 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,177 ⟶ 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,196 ⟶ 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,203 ⟶ 2,080:
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec weekday(word y, m, d) byte:
word c;
if m<3 then
m := m+10;
y := y+1
else
m := m-2
fi;
c := y/100;
y := y%100;
((26 * m - 2)/10 + d + y + y/4 + c/4 - 2*c + 777) % 7
corp
 
proc nonrec main() void:
word year;
for year from 2008 upto 2121 do
if weekday(year, 12, 25)=0 then
writeln(year)
fi
od
corp</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
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,245 ⟶ 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,275 ⟶ 2,428:
25 December 2118 is sunday
</pre>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(require 'calendar)
 
(defun sunday-p (y)
"Is Dec 25th a Sunday in this year?"
(= (calendar-day-of-week (list 12 25 y)) 0))
 
(defun xmas-sunday (a b)
"In which years in the range a, b is Dec 25th a Sunday?"
(seq-filter #'sunday-p (number-sequence a b)))
 
(print (xmas-sunday 2008 2121))</syntaxhighlight>
{{output}}
<pre>(2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</pre>
 
=={{header|Erlang}}==
 
<langsyntaxhighlight lang="erlang">% Implemented by bengt kleberg
-module(yuletide).
-export([main/0, sunday_years/2]).
Line 1,289 ⟶ 2,457:
 
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.</langsyntaxhighlight>
{{out}}
<pre>
Line 1,312 ⟶ 2,480:
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM DAY_OF_THE_WEEK
 
Line 1,342 ⟶ 2,510:
GET(K$)
END PROGRAM
</syntaxhighlight>
</lang>
{{out}}
<pre>Dec 25, 2011
Line 1,364 ⟶ 2,532:
 
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">
<lang Euphoria>
--Day of the week task from Rosetta Code wiki
--User:Lnettnay
Line 1,380 ⟶ 2,548:
end if
end for
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,401 ⟶ 2,569:
2118
</pre>
 
 
=={{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,414 ⟶ 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,452 ⟶ 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,471 ⟶ 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,484 ⟶ 2,635:
loop cr ;
 
cr yuletide</langsyntaxhighlight>
 
The code is derived from "Collected Algorithms from ACM", Volume 1 Algorithms 1-220.
Line 1,491 ⟶ 2,642:
{{works with|Fortran|90 and later}}
Based on Forth example
<langsyntaxhighlight lang="fortran">PROGRAM YULETIDE
IMPLICIT NONE
Line 1,520 ⟶ 2,671:
END FUNCTION Day_of_week
END PROGRAM YULETIDE</langsyntaxhighlight>
{{out}}
<pre>
Line 1,526 ⟶ 2,677:
</pre>
 
=={{header|GambasFōrmulæ}}==
'''[https://gambas-playground.proko.eu/?gist=b9b4e9a871e96ea6f1db467fa23669fe Click this link to run this code]'''
<lang gambas>Public Sub Main()
Dim siCount As Short
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Day_of_the_week}}
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
 
'''Solution'''
End</lang>
 
Output:
[[File:Fōrmulæ - Day of the week 01.png]]
 
[[File:Fōrmulæ - Day of the week 02.png]]
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">for y = 2008 to 2121
if (parseDate["$y-12-25"] -> ### u ###) == "7"
println[y]</syntaxhighlight>
 
{{out}}
<pre>
2011
Sunday 25 December 2011 falls on a Sunday
2016
Sunday 25 December 2016 falls on a Sunday
2022
Sunday 25 December 2022 falls on a Sunday
2033
Sunday 25 December 2033 falls on a Sunday
2039
Sunday 25 December 2039 falls on a Sunday
2044
Sunday 25 December 2044 falls on a Sunday
2050
Sunday 25 December 2050 falls on a Sunday
2061
Sunday 25 December 2061 falls on a Sunday
2067
Sunday 25 December 2067 falls on a Sunday
2072
Sunday 25 December 2072 falls on a Sunday
2078
Sunday 25 December 2078 falls on a Sunday
2089
Sunday 25 December 2089 falls on a Sunday
2095
Sunday 25 December 2095 falls on a Sunday
2101
Sunday 25 December 2101 falls on a Sunday
2107
Sunday 25 December 2107 falls on a Sunday
2112
Sunday 25 December 2112 falls on a Sunday
2118
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 1,580 ⟶ 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 1,595 ⟶ 2,751:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,620 ⟶ 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 1,630 ⟶ 2,786:
=={{header|Haskell}}==
Using the time library:
<langsyntaxhighlight lang="haskell">import Data.Time (fromGregorian)
 
import Data.Time.Calendar.WeekDate (toWeekDate)
 
--------------------- DAY OF THE WEEK --------------------
 
isXmasSunday :: Integer -> Bool
isXmasSunday year = 7 == weekDay
where
let (_, _, wday) = toWeekDate $ fromGregorian year 12 25
(_, _, weekDay) = toWeekDate $ fromGregorian year 12 25
in wday == 7
 
 
--------------------------- TEST -------------------------
main :: IO ()
main =
mapM_
putStrLn
[ "Sunday 25 December " ++<> show year ++ " is Sunday"
| year <- [2008 .. 2121] ,
, isXmasSunday year ]</lang>
]</syntaxhighlight>
{{out}}
<pre>Sunday 25 December 2011
<pre>
Sunday 25 December 2011 is Sunday2016
Sunday 25 December 2016 is Sunday2022
Sunday 25 December 2022 is Sunday2033
Sunday 25 December 2033 is Sunday2039
Sunday 25 December 2039 is Sunday2044
Sunday 25 December 2044 is Sunday2050
Sunday 25 December 2050 is Sunday2061
Sunday 25 December 2061 is Sunday2067
Sunday 25 December 2067 is Sunday2072
Sunday 25 December 2072 is Sunday2078
Sunday 25 December 2078 is Sunday2089
Sunday 25 December 2089 is Sunday2095
Sunday 25 December 2095 is Sunday2101
Sunday 25 December 2101 is Sunday2107
Sunday 25 December 2107 is Sunday2112
Sunday 25 December 2112 is Sunday2118</pre>
25 December 2118 is Sunday
</pre>
 
The built-in System.Time module can overflow at the Unix epoch in 2038:
<langsyntaxhighlight lang="haskell">import System.Time
isXmasSunday :: Int -> Bool
Line 1,696 ⟶ 2,854:
[ "25 December " ++ show year ++ " is Sunday"
| year <- [2008 .. 2121]
, isXmasSunday year ]</langsyntaxhighlight>
{{out}} on 32-bit machine:
<pre>
Line 1,726 ⟶ 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 1,738 ⟶ 2,896:
</pre>
 
== {{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 1,751 ⟶ 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 1,793 ⟶ 2,951:
return d_code[(C + Y + M + day) % 7 + 1]
end</langsyntaxhighlight>
 
{{out}}
Line 1,799 ⟶ 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 1,811 ⟶ 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 1,843 ⟶ 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 1,869 ⟶ 3,020:
====Functional composition====
 
<langsyntaxhighlight JavaScriptlang="javascript">(function () {
'use strict';
 
Line 1,889 ⟶ 3,040:
.filter(isXmasSunday);
 
})();</langsyntaxhighlight>
 
{{Out}}
Line 1,896 ⟶ 3,047:
 
===ES6===
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
'"use strict'";
 
// main :: IO ()
const main = () => {
const
xs = enumFromTo(2008, )(2121)
.filter(xmasIsSunday);
 
return (
console.log(xs),
Line 1,918 ⟶ 3,070:
 
// enumFromTo :: Int -> Int -> [Int]
const enumFromTo = (m, n) =>
n => Array.from({
length: 1 + n - m
}, (_, i) => m + i);
 
// 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 1,947 ⟶ 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
[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118]
 
=={{header|JuliaJsish}}==
Jsi does not yet implement the Javascript ''Date'' object. ''strftime' and ''strptime'' functions are used here instead.
{{works with|Julia|0.6}}
 
<syntaxhighlight lang="javascript">/* Day of the week, December 25th on a Sunday */
<lang julia>using Base.Dates
for (var year = 2008; year <= 2121; year++) {
var xmas = strptime(year + '/12/25', '%Y/%m/%d');
var weekDay = strftime(xmas, '%w');
if (weekDay == 0) puts(year);
}
 
/*
=!EXPECTSTART!=
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
=!EXPECTEND!=
*/</syntaxhighlight>
 
{{out}}
<pre>prompt$ jsish -u dayOfTheWeek.jsi
[PASS] dayOfTheWeek.jsi</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Dates
 
lo, hi = 2008, 2121
Line 1,968 ⟶ 3,154:
 
println("Years from $lo to $hi having Christmas on Sunday: ")
foreach(println, year.(xmas))</langsyntaxhighlight>
 
{{out}}
Line 1,991 ⟶ 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,008 ⟶ 3,231:
calendar.add(Calendar.YEAR, 1)
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,032 ⟶ 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,057 ⟶ 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,081 ⟶ 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,105 ⟶ 3,354:
 
=={{header|LiveCode}}==
<langsyntaxhighlight LiveCodelang="livecode">function xmasSunday startDate endDate
convert the long date to dateitems
put it into xmasDay
Line 2,117 ⟶ 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,153 ⟶ 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,161 ⟶ 3,410:
'''Library:''' [http://luaforge.net/projects/date/ LuaDate]
 
<langsyntaxhighlight Lualang="lua">require("date")
 
for year=2008,2121 do
Line 2,167 ⟶ 3,416:
print(year)
end
end</langsyntaxhighlight>
 
{{out}}
Line 2,192 ⟶ 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,198 ⟶ 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,218 ⟶ 3,467:
 
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,241 ⟶ 3,490:
 
=={{header|M4}}==
<langsyntaxhighlight M4lang="m4">divert(-1)
 
define(`for',
Line 2,259 ⟶ 3,508:
 
for(`yr',2008,2121,
`ifelse(eval(julianxmas(yr)%7==6),1,`yr ')')</langsyntaxhighlight>
 
{{out}}
Line 2,268 ⟶ 3,517:
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">xmas:= proc()
local i, dt;
for i from 2008 to 2121 by 1 do
Line 2,278 ⟶ 3,527:
end proc;
 
xmas();</langsyntaxhighlight>
 
{{Out|Output}}
Line 2,301 ⟶ 3,550:
</pre>
 
Or simply:
 
<syntaxhighlight lang="maple">select(y->Calendar:-DayOfWeek(Date(y,12,25))=1,[$2008..2121]);</syntaxhighlight>
 
{{out}}
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
 
=={{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,337 ⟶ 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,346 ⟶ 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]
ИП8 ИП6 1 2 * - 1 4 - 3
0 , 5 9 * [x] + 2 9 +
ИП7 + П4 ИП4 7 / [x] 7 * -
x=0 64 ИП9 С/П ИП9 1 + П9 БП 06</syntaxhighlight>
 
''Input:'' РX: starting year.
 
''Output:'' the year in which Christmas falls on a Sunday. For example, enter ''2008'', the first result: ''2018'' (''January 7, 2018'' is Sunday).
 
=={{header|Modula-3}}==
Line 2,354 ⟶ 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,381 ⟶ 3,665:
END;
END;
END Yule.</langsyntaxhighlight>
 
{{out}}
Line 2,391 ⟶ 3,675:
2038 is the last year we can specify
</pre>
 
=={{header|МК-61/52}}==
<lang>П9 7 П7 1 П8 НОП ИП8 2 2 -
1 0 / [x] П6 ИП9 + 1 8 9
9 - 3 6 5 , 2 5 * [x]
ИП8 ИП6 1 2 * - 1 4 - 3
0 , 5 9 * [x] + 2 9 +
ИП7 + П4 ИП4 7 / [x] 7 * -
x=0 64 ИП9 С/П ИП9 1 + П9 БП 06</lang>
 
''Input:'' РX: starting year.
 
''Output:'' the year in which Christmas falls on a Sunday. For example, enter ''2008'', the first result: ''2018'' (''January 7, 2018'' is Sunday).
 
=={{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,427 ⟶ 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
</pre>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">import Nanoquery.Util
// loop through the years 2008 through 2121
for year in range(2008, 2121)
if (new(Date,"12/25/" + str(year)).getDayOfWeek() = "Sunday")
println "In " + year + ", December 25th is a Sunday."
end if
end for</syntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
Line 2,451 ⟶ 3,732:
 
return
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,459 ⟶ 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 2,650 ⟶ 3,931:
method modulo(N = int, D = int) inheritable static binary returns int
return (D + (N // D)) // D
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,664 ⟶ 3,945:
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import times
 
var timeinfo = getLocalTime getTime()
timeinfo.monthday = 25
timeinfo.month = mDec
for year in 2008..2121:
timeinfo.if getDayOfWeek(25, mDec, year) == yeardSun:
stdout.write year, ' '
if getLocalTime(timeInfoToTime timeinfo).weekday == dSun:
echo ""</syntaxhighlight>
stdout.write year," "</lang>
 
{{out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 </pre>
Line 2,678 ⟶ 3,957:
=={{header|Oberon-2}}==
{{works with|oo2c version 2}}
<langsyntaxhighlight lang="oberon2">
MODULE DayOfWeek;
IMPORT NPCT:Dates, Out;
Line 2,692 ⟶ 3,971:
END
END DayOfWeek.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,714 ⟶ 3,993:
</pre>
{{works with|AOS}}
<syntaxhighlight lang="oberon2">
<lang Oberon2>
MODULE DaysOfWeek; (** AUTHOR ""; PURPOSE ""; *)
 
Line 2,734 ⟶ 4,013:
 
END DaysOfWeek.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,761 ⟶ 4,040:
{{works with|Cocoa}}
 
<langsyntaxhighlight lang="objc">#import <Foundation/Foundation.h>
 
int main()
Line 2,782 ⟶ 4,061:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 2,807 ⟶ 4,086:
=={{header|OCaml}}==
{{trans|C}}
<langsyntaxhighlight lang="ocaml">#load "unix.cma"
open Unix
 
Line 2,826 ⟶ 4,105:
raise e
done
with _ -> ()</langsyntaxhighlight>
 
{{out}} of a run on a 32 bit machine
Line 2,843 ⟶ 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 2,860 ⟶ 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 2,885 ⟶ 4,164:
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">import: date
seqFrom(2008, 2121) filter(#[ 12 25 Date newDate dayOfWeek Date.SUNDAY == ]) .</langsyntaxhighlight>
{{out}}
<pre>
Line 2,893 ⟶ 4,172:
 
=={{header|ooRexx}}==
===Christmas===
<lang ooRexx>date = .datetime~new(2008, 12, 25)
<syntaxhighlight lang="oorexx">date = .datetime~new(2008, 12, 25)
lastdate = .datetime~new(2121, 12, 25)
 
Line 2,905 ⟶ 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===
<syntaxhighlight lang="oorexx">/* REXX */
Parse Arg yyyymmdd
If arg(1)='' |,
arg(1)='?' Then Do
Say 'rexx wd yyyymmdd will show which weekday that is'
Exit
End
Parse Var yyyymmdd y +4 m +2 d
wd=.Array~of('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')
dt=.DateTime~new(y,m,d)
say yyyymmdd 'is a' wd[dt~weekday]</syntaxhighlight>
{{out}}
<pre>H:\>rexx wd ?
rexx wd yyyymmdd will show which weekday that is
 
H:\>rexx wd 20211206
20211206 is a Monday </pre>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">
njd(D) =
{
Line 2,921 ⟶ 4,219:
 
for (y = 2008, 2121, if (njd([y,12,25]) % 7 == 1, print(y)));
</syntaxhighlight>
</lang>
 
Output:
Line 2,949 ⟶ 4,247:
 
=={{header|Peloton}}==
<langsyntaxhighlight lang="sgml"><@ SAI>
<@ ITEFORLI3>2121|2008|
<@ LETVARCAP>Christmas Day|25-Dec-<@ SAYVALFOR>...</@></@>
Line 2,957 ⟶ 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 2,969 ⟶ 4,267:
</#>
</#></langsyntaxhighlight>
 
{{out}}
Line 2,992 ⟶ 4,290:
=={{header|Perl}}==
 
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use Time::Local;
Line 3,007 ⟶ 4,305:
}
 
exit 0;</langsyntaxhighlight>
 
{{out}}
Line 3,022 ⟶ 4,320:
 
Using the DateTime module from CPAN:
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 3,039 ⟶ 4,337:
}
 
exit 0;</langsyntaxhighlight>
or shorter:
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 3,051 ⟶ 4,349:
}
 
exit 0;</langsyntaxhighlight>
{{out}}
<pre>
Line 3,074 ⟶ 4,372:
 
Alternatively in one line using grep (read from right to left):
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 3,081 ⟶ 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>
 
=={{header|Perl 6}}==
 
{{works with|Rakudo|2010.07}}
 
As Perl 5, except <code>DateTime</code> is built-in, so you don't need to download a module of that name:
 
<lang perl6>say join ' ', grep { Date.new($_, 12, 25).day-of-week == 7 }, 2008 .. 2121;</lang>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
<lang Phix>sequence res = {}
<!--<syntaxhighlight lang="phix">-->
for y=2008 to 2121 do
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Day_of_the_week.exw</span>
if day_of_week(y,12,25)=1 then
<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>
res = append(res,y)
<span style="color: #008080;">for</span> <span style="color: #000000;">y<span style="color: #0000FF;">=<span style="color: #000000;">2008</span> <span style="color: #008080;">to</span> <span style="color: #000000;">2121</span> <span style="color: #008080;">do</span>
end if
<span style="color: #008080;">if</span> <span style="color: #7060A8;">day_of_week<span style="color: #0000FF;">(<span style="color: #000000;">y<span style="color: #0000FF;">,<span style="color: #000000;">12<span style="color: #0000FF;">,<span style="color: #000000;">25<span style="color: #0000FF;">,<span style="color: #004600;">true<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #008000;">"Sunday"</span> <span style="color: #008080;">then</span>
end for
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append<span style="color: #0000FF;">(<span style="color: #000000;">res<span style="color: #0000FF;">,<span style="color: #000000;">y<span style="color: #0000FF;">)</span>
?res</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?<span style="color: #000000;">res
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 3,108 ⟶ 4,402:
=={{header|PHP}}==
 
<langsyntaxhighlight lang="php"><?php
for($i=2008; $i<2121; $i++)
{
Line 3,117 ⟶ 4,411:
}
}
?></langsyntaxhighlight>
 
{{out}}
Line 3,139 ⟶ 4,433:
25 Dec 2118 is Sunday
</pre>
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">go =>
L = [Year : Year in 2008..2121, dow(Year, 12, 25) == 0],
println(L),
println(len=L.length),
nl.
 
% Day of week, Sakamoto's method
dow(Y, M, D) = R =>
T = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4],
if M < 3 then
Y := Y - 1
end,
R = (Y + Y // 4 - Y // 100 + Y // 400 + T[M] + D) mod 7.
</syntaxhighlight>
 
{{out}}
<pre>[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118]
len = 17</pre>
 
=={{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,170 ⟶ 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,179 ⟶ 4,542:
put skip list ('Christmas day ' || i || ' is a Sunday');
end;
</syntaxhighlight>
</lang>
 
==={{header|PL/I-80}}===
<syntaxhighlight lang="pl/i">/* Test of PL/I-80 routine to determine day of the week */
 
sunday_christmas:
proc options (main);
%replace
sunday by 0;
dcl
(year, w) fixed bin(15);
put skip list ('Christmas will fall on Sunday in these years:');
do year = 2008 to 2121;
w = weekday((year),12,25);
if w = sunday then
put skip edit (year) (f(4));
end;
 
stop;
 
/*
* Return day of week (Sun=0, Mon=1, etc.) for a given
* yr, mo, da using Zeller's congruence
*/
weekday:
proc (yr, mo, da) returns (fixed bin(15));
dcl (yr, mo, da) fixed bin(15);
dcl (c, y, m, d, z) fixed bin(15);
y = yr; /* make local copies */
m = mo;
d = da;
if m < 3 then
do;
m = m + 10;
y = y - 1;
end;
else m = m - 2;
c = y / 100;
y = mod(y, 100);
z = (26 * m - 2) / 10;
z = z + d + y + (y/4) + (c/4) - 2 * c + 777;
return (mod(z, 7));
end weekday;
 
end sunday_christmas;
</syntaxhighlight>
{{out}}
<pre>Christmas will fall on Sunday in these years:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
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,220 ⟶ 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,248 ⟶ 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,258 ⟶ 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,270 ⟶ 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,282 ⟶ 4,772:
</pre>
 
=={{header|PureBasicProlog}}==
Works with SWI-Prolog;
PureBasic's internal Date() is limited between 1970-01-01 00:00:00 and 2038-01-19 03:14:07
<syntaxhighlight lang="prolog">main() :-
<lang PureBasic>For i=2008 To 2037
christmas_days_falling_on_sunday(2011, 2121, SundayList),
If DayOfWeek(Date(i,12,25,0,0,0))=0
PrintNwriteln(Str(i)SundayList).
 
EndIf
christmas_days_falling_on_sunday(StartYear, EndYear, SundayList) :-
Next</lang>
numlist(StartYear, EndYear, YearRangeList),
include(is_christmas_day_a_sunday, YearRangeList, SundayList).
is_christmas_day_a_sunday(Year) :-
Date = date(Year, 12, 25),
day_of_the_week(Date, DayOfTheWeek),
DayOfTheWeek == 7.
</syntaxhighlight>
{{out}}
<pre>?- main.
[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118]
true.</pre>
 
=={{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 3,301 ⟶ 4,803:
 
Or, in terms of datetime:
{{Works with|Python|3.7}}
<lang python>import datetime
<syntaxhighlight lang="python">'''Days of the week'''
 
from datetime import date
from itertools import islice
 
 
# xmasIsSunday :: Int -> Bool
def xmasIsSunday(y):
'''True if Dec 25 in the given year is a Sunday.'''
return 6 == datetime.date(y, 12, 25).weekday()
return 6 == date(y, 12, 25).weekday()
 
 
# main :: IO ()
def main():
'''Years between 2008 and 2121 with 25 Dec on a Sunday'''
for x in filter(xmasIsSunday, enumFromTo(2008)(2121)):
 
print (x)
xs = list(filter(
xmasIsSunday,
enumFromTo(2008)(2121)
))
total = len(xs)
print(
fTable(main.__doc__ + ':\n\n' + '(Total ' + str(total) + ')\n')(
lambda i: str(1 + i)
)(str)(index(xs))(
enumFromTo(0)(total - 1)
)
)
 
 
# GENERIC -------------------------------------------------
 
# enumFromTo :: (Int ->, Int) -> [Int]
def enumFromTo(m):
'''Integer enumeration from m to n.'''
return lambda n: list(range(m, 1 + n))
 
 
# index (!!) :: [a] -> Int -> a
def index(xs):
'''Item at given (zero-based) index.'''
return lambda n: None if 0 > n else (
xs[n] if (
hasattr(xs, "__getitem__")
) else next(islice(xs, n, None))
)
 
 
 
# FORMATTING ---------------------------------------------
# fTable :: String -> (a -> String) ->
# (b -> String) -> (a -> b) -> [a] -> String
def fTable(s):
'''Heading -> x display function -> fx display function ->
f -> xs -> tabular string.
'''
def go(xShow, fxShow, f, xs):
ys = [xShow(x) for x in xs]
w = max(map(len, ys))
return s + '\n' + '\n'.join(map(
lambda x, y: y.rjust(w, ' ') + ' -> ' + fxShow(f(x)),
xs, ys
))
return lambda xShow: lambda fxShow: lambda f: lambda xs: go(
xShow, fxShow, f, xs
)
 
 
# MAIN --
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>
{{Out}}
<pre>Years between 2008 and 2121 with 25 Dec on a Sunday:
<pre>2011
 
2016
(Total 17)
2022
 
2033
1 -> 2011
2039
2 -> 2016
2044
3 -> 2022
2050
4 -> 2033
2061
5 -> 2039
2067
6 -> 2044
2072
7 -> 2050
2078
8 -> 2061
2089
9 -> 2067
2095
10 -> 2072
2101
11 -> 2078
2107
12 -> 2089
2112
13 -> 2095
2118</pre>
14 -> 2101
15 -> 2107
16 -> 2112
17 -> 2118</pre>
 
=={{header|Quackery}}==
 
Using Tomohiko Sakamoto's algorithm.
 
<syntaxhighlight lang="quackery"> [ over 3 < if [ 1 - ]
dup 4 / over +
over 100 / -
swap 400 / +
swap 1 -
[ table
0 3 2 5 0 3
5 1 4 6 2 4 ]
+ + 7 mod ] is dayofweek ( day month year --> weekday )
 
say "The 25th of December is a Sunday in: " cr
2121 1+ 2008 - times
[ 25 12 i^ 2008 + dayofweek
0 = if [ i^ 2008 + echo sp ] ] </syntaxhighlight>
 
{{out}}
 
<pre>The 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|R}}==
<langsyntaxhighlight Rlang="r">years <- 2008:2121
xmas <- as.POSIXlt(paste0(years, '/12/25'))
years[xmas$wday==0]
Line 3,364 ⟶ 4,943:
 
# Under MS Windows, write instead
Sys.setlocale("LC_ALL", "English")</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
 
Line 3,378 ⟶ 4,957:
(for ([y (in-range 2008 2121)] #:when (xmas-on-sunday? y))
(displayln y))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
 
{{works with|Rakudo|2010.07}}
 
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" line>say join ' ', grep { Date.new($_, 12, 25).day-of-week == 7 }, 2008 .. 2121;</syntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Yuletide Holiday"
URL: http://rosettacode.org/wiki/Yuletide_Holiday
Line 3,389 ⟶ 4,977:
d: to-date reduce [y 12 25]
if 7 = d/weekday [prin [y ""]]
]</langsyntaxhighlight>
 
{{out}}
Line 3,395 ⟶ 4,983:
 
=={{header|Red}}==
<langsyntaxhighlight Redlang="red">Red []
repeat yy 114 [
d: to-date reduce [25 12 (2007 + yy )]
Line 3,410 ⟶ 4,998:
d/year: d/year + 1
]
</syntaxhighlight>
</lang>
{{out}}<pre>25-Dec-2011
25-Dec-2016
Line 3,448 ⟶ 5,036:
>>
</pre>
 
=={{header|REXX}}==
===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>2011
<pre>
2011
2016
2022
Line 3,470 ⟶ 5,061:
2107
2112
2118</pre>
</pre>
 
===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>
'''output''' is the same as above
 
===using DATE iso===
Works with Regina REXX only.
Works with ooRexx
 
The extended &nbsp; DATE &nbsp; parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
 
Programming note: &nbsp; The &nbsp; '''ISO''' &nbsp; option of the &nbsp; '''date''' &nbsp; BIF is a Regina extension.
 
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 3,502 ⟶ 5,093:
 
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 inputinputs:}}
<pre>
December 25th, 2011 falls on a Sunday.
Line 3,526 ⟶ 5,117:
 
===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 3,537 ⟶ 5,128:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
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>
December 25th, 2011 falls on a Sunday.
Line 3,562 ⟶ 5,153:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
for n = 2008 to 2121
if n < 2100 leap = n - 1900 else leap = n - 1904 ok
Line 3,568 ⟶ 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 3,596 ⟶ 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 3,616 ⟶ 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 3,651 ⟶ 5,240:
let years = (2008..2121).filter(|&y| Local.ymd(y, 12, 25).weekday() == Weekday::Sun).collect::<Vec<i32>>();
println!("Years = {:?}", years);
}</langsyntaxhighlight>
 
Output:
Line 3,658 ⟶ 5,247:
 
=={{header|SAS}}==
<langsyntaxhighlight lang="sas">data _null_;
do y=2008 to 2121;
a=mdy(12,25,y);
if weekday(a)=1 then put y;
end;
run;
 
/* 2011 2016 2022 2033 2039 2044 2050 2061 2067
2072 2078 2089 2095 2101 2107 2112 2118 */</langsyntaxhighlight>
 
=={{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
{{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|Scala}}==
{{libheader|Scala}}
===JDK (discouraged) ===
<langsyntaxhighlight lang="scala">import java.util.{ Calendar, GregorianCalendar }
import Calendar.{ DAY_OF_WEEK, DECEMBER, SUNDAY }
 
Line 3,743 ⟶ 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 3,758 ⟶ 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 3,775 ⟶ 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 3,801 ⟶ 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 3,807 ⟶ 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 3,825 ⟶ 5,359:
 
(task)
; (2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</langsyntaxhighlight>
 
=={{header|Seed7}}==
Line 3,831 ⟶ 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 3,843 ⟶ 5,377:
end if;
end for;
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 3,863 ⟶ 5,397:
Christmas comes on a sunday in 2112
Christmas comes on a sunday in 2118
</pre>
 
=={{header|SenseTalk}}==
<syntaxhighlight lang="sensetalk">// In what years between 2008 and 2121 will the 25th of December be a Sunday?
 
repeat with year = 2008 to 2121
set Christmas to "12/25/" & year
if the WeekDayName of Christmas is Sunday then
put "Christmas in " & year & " falls on a Sunday"
end if
end repeat</syntaxhighlight>
{{out}}
<pre>
Christmas in 2011 falls on a Sunday
Christmas in 2016 falls on a Sunday
Christmas in 2022 falls on a Sunday
Christmas in 2033 falls on a Sunday
Christmas in 2039 falls on a Sunday
Christmas in 2044 falls on a Sunday
Christmas in 2050 falls on a Sunday
Christmas in 2061 falls on a Sunday
Christmas in 2067 falls on a Sunday
Christmas in 2072 falls on a Sunday
Christmas in 2078 falls on a Sunday
Christmas in 2089 falls on a Sunday
Christmas in 2095 falls on a Sunday
Christmas in 2101 falls on a Sunday
Christmas in 2107 falls on a Sunday
Christmas in 2112 falls on a Sunday
Christmas in 2118 falls on a Sunday
</pre>
 
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">require('Time::Local')
 
for year in (2008 .. 2121) {
Line 3,875 ⟶ 5,439:
say "25 Dec #{year} is Sunday"
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,896 ⟶ 5,460:
25 Dec 2118 is Sunday
</pre>
 
=={{header|Simula}}==
{{trans|Sinclair ZX81 BASIC}}
<syntaxhighlight lang="simula">BEGIN
INTEGER M,D,Y;
M := 12;
D := 25;
FOR Y := 2008 STEP 1 UNTIL 2121 DO BEGIN
INTEGER W,A,MM,YY;
A := (14 - M)//12;
MM := M + 12*A - 2;
YY := Y - A;
W := D + ((13*MM - 1)//5) + YY + (YY//4) - (YY//100) + (YY//400);
W := MOD(W,7);
IF W = 0 THEN
BEGIN OUTINT(Y,0);
OUTIMAGE;
END;
END;
END.</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{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 3,922 ⟶ 5,524:
25-Dec-2112
25-Dec-2118</pre>
 
=={{header|SparForte}}==
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.)
 
<syntaxhighlight 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
from dual
connect by level <= 2121 - 2008 + 1
)
where to_char(dt, 'Dy', 'nls_date_language=English') = 'Sun'
order by 1
;</syntaxhighlight>
 
 
{{out}}
<pre>
YEAR_WITH_XMAS_ON_SUNDAY
------------------------
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
 
17 rows selected.</pre>
 
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):
 
 
<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}}==
<syntaxhighlight lang="sml">(* Call: yearsOfSundayXmas(2008, 2121) *)
fun yearsOfSundayXmas(fromYear, toYear) =
if fromYear>toYear then
()
else
let
val d = Date.date {year=fromYear, month=Date.Dec, day=25,
hour=0, minute=0, second=0,
offset=SOME Time.zeroTime}
val wd = Date.weekDay d
in
if wd=Date.Sun then
(
print(Int.toString fromYear ^ "\n");
yearsOfSundayXmas(fromYear+1, toYear)
)
else
yearsOfSundayXmas(fromYear+1, toYear)
end;</syntaxhighlight>
 
{{out}}
<pre>- yearsOfSundayXmas(2008, 2121);
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|Stata}}==
 
<lang stata>clear
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.
set obs 114
<syntaxhighlight lang="stata">clear
sca n=2121-2008+1
set obs `=n'
gen year=2007+_n
list if dow(mdy(12,25,year))==0, noobs sep(500)
 
+------+
Line 3,949 ⟶ 5,696:
| 2112 |
| 2118 |
+------+</langsyntaxhighlight>
 
=== Mata ===
 
<syntaxhighlight lang="mata">year=2008::2121
select(year,dow(mdy(12,25,year)):==0)</syntaxhighlight>
 
=={{header|Suneido}}==
<langsyntaxhighlight Suneidolang="suneido">year = 2008
while (year <= 2121)
{
Line 3,958 ⟶ 5,710:
Print(year)
++year
}</langsyntaxhighlight>
{{out}}
<pre>2011
Line 3,979 ⟶ 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,016 ⟶ 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,022 ⟶ 5,775:
puts "xmas $y is a sunday"
}
}</langsyntaxhighlight>
{{out}}
<pre>xmas 2011 is a sunday
Line 4,041 ⟶ 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 4,078 ⟶ 5,803:
IF (dayofweek==7) PRINT year
ENDLOOP
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,099 ⟶ 5,824:
2112
2118
</pre>
 
== {{header|TypeScript}} ==
{{trans|Minimal BASIC}}
<syntaxhighlight lang="javascript">
// Find years with Sunday Christmas
var f = 2008;
var t = 2121;
console.log(`Sunday Christmases ${f} - ${t}`);
for (y = f; y <= t; y++) {
var x = (y * 365) + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) - 6;
if (x % 7 == 0)
process.stdout.write(`${y}\t`);
}
process.stdout.write("\n");
</syntaxhighlight>
{{out}}
<pre>
Sunday Christmases 2008 - 2121
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
Line 4,108 ⟶ 5,853:
 
{{works with|bash}}
<langsyntaxhighlight lang="bash">#! /bin/bash
 
for (( i=2008; i<=2121; ++i ))
Line 4,115 ⟶ 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 4,129 ⟶ 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 4,156 ⟶ 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 4,179 ⟶ 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 4,207 ⟶ 5,952:
date with the weekday included. The output is then filtered for Sundays.
 
<langsyntaxhighlight Ursalalang="ursala">#import std
#import nat
#import stt
Line 4,215 ⟶ 5,960:
#show+
 
sunday_years = ~&zS sep` * =]'Sun'*~ christmases</langsyntaxhighlight>
{{out}}
<pre>2011
Line 4,234 ⟶ 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 4,289 ⟶ 5,988:
Num_Ins(#3, NOCR)
}
}</langsyntaxhighlight>
 
{{out}}
Line 4,297 ⟶ 5,996:
 
=={{header|Visual Objects}}==
<langsyntaxhighlight lang="visualfoxpro">
local i as dword
Line 4,305 ⟶ 6,004:
endif
next i
</syntaxhighlight>
</lang>
 
{{out}}
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|V (Vlang)}}==
Updated for Vlang version 0.2.2
<syntaxhighlight lang="go">import time
 
fn main() {
for year := 2008; year <= 2121; year++ {
date := time.parse('${year}-12-25 00:00:00') or { continue }
if date.long_weekday_str() == 'Sunday' {
println('December 25 ${year} is a ${date.long_weekday_str()}')
}
}
}</syntaxhighlight>
 
{{out}}
<pre>
December 25 2011 is a Sunday
December 25 2016 is a Sunday
December 25 2022 is a Sunday
December 25 2033 is a Sunday
December 25 2039 is a Sunday
December 25 2044 is a Sunday
December 25 2050 is a Sunday
December 25 2061 is a Sunday
December 25 2067 is a Sunday
December 25 2072 is a Sunday
December 25 2078 is a Sunday
December 25 2089 is a Sunday
December 25 2095 is a Sunday
December 25 2101 is a Sunday
December 25 2107 is a Sunday
December 25 2112 is a Sunday
December 25 2118 is a Sunday
</pre>
 
=={{header|VTL-2}}==
{{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.
<syntaxhighlight lang="vtl2">1000 #=2000
1010 R=!
1020 N=M
1030 X=Y
1040 #=N>3*1070
1050 N=N+12
1060 X=X-1
1070 J=X/100
1080 K=%
1090 W=N+1*26/10+D+K+(K/4)+(J/4)+(5*J)/7*0+%
1100 #=R
2000 ?="25th of December is a Sunday in";
2010 Y=2008
2020 M=12
2030 D=25
2040 #=1010
2050 #=W=1=0*2080
2060 $=32
2070 ?=Y
2080 Y=Y+1
2090 #=Y<2121*2040
2100 ?=""</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|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}}
<syntaxhighlight lang="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)
}</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|XPL0}}==
Line 4,321 ⟶ 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 4,334 ⟶ 6,128:
if WeekDay(Year, 12, 25) = 1 then \25th of December is a Sunday
[IntOut(0, Year); CrLf(0)];
]</langsyntaxhighlight>
 
{{out}}
Line 4,356 ⟶ 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 4,406 ⟶ 6,182:
 
=={{header|zonnon}}==
<langsyntaxhighlight lang="zonnon">
module Main;
(*Access to Mono System package *)
Line 4,418 ⟶ 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