Day of the week: Difference between revisions
Content added Content deleted
TechAscent (talk | contribs) |
(Dialects of BASIC moved to the BASIC section.) |
||
Line 507: | Line 507: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
<syntaxhighlight lang="awk"> |
||
# syntax: GAWK -f DAY_OF_THE_WEEK.AWK |
# syntax: GAWK -f DAY_OF_THE_WEEK.AWK |
||
Line 520: | Line 519: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
<b>Works with:</b> FreeBASIC <br> |
|||
This program needs the modulo function because there is a bug in the built in modulo function. |
|||
<syntaxhighlight lang="basic">Declare Function modulo(x As Double, y As Double) As Double |
|||
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 |
|||
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</syntaxhighlight> |
|||
==={{header|Applesoft BASIC}}=== |
==={{header|Applesoft BASIC}}=== |
||
{{trans|Commodore BASIC}} |
{{trans|Commodore BASIC}} |
||
Line 633: | Line 582: | ||
2112 |
2112 |
||
2118</pre> |
2118</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|Commodore BASIC}}=== |
==={{header|Commodore BASIC}}=== |
||
Line 662: | Line 621: | ||
2095 2101 2107 2112 |
2095 2101 2107 2112 |
||
2118</pre> |
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}}=== |
==={{header|FreeBASIC}}=== |
||
Line 706: | Line 680: | ||
Dec 25 2112 |
Dec 25 2112 |
||
Dec 25 2118</pre> |
Dec 25 2118</pre> |
||
<syntaxhighlight lang="basic">Declare Function modulo(x As Double, y As Double) As Double |
|||
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 |
<syntaxhighlight lang="freebasic">' version 17-06-2015 |
||
' Weekday And DateSerial only works with #Include "vbcompat.bi" |
' Weekday And DateSerial only works with #Include "vbcompat.bi" |
||
Line 741: | Line 763: | ||
25-12-2112 |
25-12-2112 |
||
25-12-2118</pre> |
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}}=== |
==={{header|GW-BASIC}}=== |
||
Line 770: | Line 849: | ||
180 LET DAYWEEK=W-7*INT(W/7) |
180 LET DAYWEEK=W-7*INT(W/7) |
||
190 END DEF</syntaxhighlight> |
190 END DEF</syntaxhighlight> |
||
==={{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}}=== |
==={{header|Minimal BASIC}}=== |
||
Line 788: | Line 881: | ||
140 END |
140 END |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
==={{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|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|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}}=== |
==={{header|Sinclair ZX81 BASIC}}=== |
||
Line 824: | Line 1,050: | ||
2118</pre> |
2118</pre> |
||
==={{header| |
==={{header|TI-83 BASIC}}=== |
||
{{Works with|TI-84+/SE}} only |
|||
<b>Works with:</b> [https://en.wikipedia.org/wiki/Sinclair_QL ''Sinclair QL''] <br> |
|||
<syntaxhighlight lang="ti83b"> |
|||
...having a structured [https://en.wikipedia.org/wiki/SuperBASIC ''BASIC''] with MOD and quite unlike the ZX81's "first-generation" |
|||
:For(A,2008,2121 |
|||
BASIC that's rather like using a calculator (also without an integer type). Even so, it's worth the minor effort to optimise the |
|||
:If dayofWk(A,12,25)=1 |
|||
code for the task at hand, as done below - which if implemented for the ZX81's routine would make it finish in a fraction of a |
|||
:Disp A |
|||
second, even in SLOW mode, as multiplying by 13 with a division by 5 is slower than by 256 alone, as well as that two divisions by |
|||
:End |
|||
multiples of 100 are much slower than one by 16 as at the link. N.B. by relying on strings to have 4-digit years, this routine is not y10k-compliant |
|||
<syntaxhighlight lang="qbasic"> |
|||
AUTO 100,10 |
|||
DEF PROC Iso(S,O) |
|||
REM passing starting & ending years via integers S & O |
|||
LOCal y$,m%,d%,i$,n%,w% |
|||
LET m%=12 : d%=25 |
|||
REM m% & d% are constants, so avoid recalculating n% (=48) each iteration |
|||
LET i$=m%*256+ 19300 : n%=i$(2 TO 3)+ d% |
|||
FOR count=S TO O |
|||
LET y$=count : w%=(y$(1 TO 2)&"32"DIV 16+ count DIV 4+ count+ n%)MOD 7 |
|||
REM otherwise w%=(y$(1 TO 2)&"16"DIV 16+ count DIV 4+ count)MOD 7 |
|||
REM = further optimisation beyond skipping irrelevant years: |
|||
IF w%=0 THEN PRINT count : count = count+ 4 |
|||
END FOR count |
|||
END DEF Iso |
|||
ctrl+space |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 868: | Line 1,075: | ||
2107 |
2107 |
||
2112 |
2112 |
||
2118 |
2118 |
||
Done</pre> |
|||
==={{header|Tiny BASIC}}=== |
==={{header|Tiny BASIC}}=== |
||
Line 908: | Line 1,116: | ||
2112 |
2112 |
||
2118</pre> |
2118</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|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}}== |
=={{header|Batch File}}== |
||
Line 950: | Line 1,235: | ||
Dec 25, 2118 is a Sunday. |
Dec 25, 2118 is a Sunday. |
||
Press any key to continue . . .</pre> |
Press any key to continue . . .</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|bc}}== |
=={{header|bc}}== |
||
Line 2,128: | Line 2,403: | ||
<syntaxhighlight lang="factor">USING: calendar math.ranges prettyprint sequences ; |
<syntaxhighlight lang="factor">USING: calendar math.ranges prettyprint sequences ; |
||
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .</syntaxhighlight> |
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .</syntaxhighlight> |
||
=={{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|Forth}}== |
=={{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. |
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. |
||
<syntaxhighlight lang="forth"> |
<syntaxhighlight lang="forth"> |
||
Line 2,270: | Line 2,529: | ||
2112 |
2112 |
||
2118 |
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> |
</pre> |
||
Line 2,867: | Line 3,068: | ||
12/25/2112 is a Sunday |
12/25/2112 is a Sunday |
||
12/25/2118 is a Sunday</pre> |
12/25/2118 is a Sunday</pre> |
||
=={{header|Liberty 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|Lingo}}== |
=={{header|Lingo}}== |
||
Line 4,225: | Line 4,410: | ||
[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118] |
[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118] |
||
true.</pre> |
true.</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|Python}}== |
=={{header|Python}}== |
||
Line 4,674: | Line 4,851: | ||
(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/]) |
(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}}== |
|||
<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|Rust}}== |
=={{header|Rust}}== |
||
Line 4,711: | Line 4,865: | ||
<pre>Years = [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118] |
<pre>Years = [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118] |
||
</pre> |
</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 |
|||
2011 |
|||
2033 |
|||
2039 |
|||
2044 |
|||
2050 |
|||
2061 |
|||
2067 |
|||
2072 |
|||
2078 |
|||
2089 |
|||
2095 |
|||
2101 |
|||
2107 |
|||
2112 |
|||
2118</pre> |
|||
=={{header|SAS}}== |
=={{header|SAS}}== |
||
Line 4,982: | Line 5,080: | ||
25 Dec 2118 is Sunday |
25 Dec 2118 is Sunday |
||
</pre> |
</pre> |
||
=={{header|Simula}}== |
=={{header|Simula}}== |
||
{{trans|Sinclair ZX81 BASIC}} |
{{trans|Sinclair ZX81 BASIC}} |
||
Line 5,256: | Line 5,355: | ||
xmas 2112 is a sunday |
xmas 2112 is a sunday |
||
xmas 2118 is a sunday</pre> |
xmas 2118 is a sunday</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|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
Line 5,469: | Line 5,540: | ||
2112 |
2112 |
||
2118</pre> |
2118</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|Vedit macro language}}== |
=={{header|Vedit macro language}}== |
||
Line 5,686: | Line 5,711: | ||
2118 |
2118 |
||
</pre> |
</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|zkl}}== |
=={{header|zkl}}== |
||
Line 5,753: | Line 5,760: | ||
2017-12-05 :Tuesday |
2017-12-05 :Tuesday |
||
</pre> |
</pre> |
||
=={{header|ZX Spectrum Basic}}== |
|||
{{trans|BASIC}} |
|||
<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> |