Day of the week: Difference between revisions
m
syntax highlighting fixup automation
(Applesoft BASIC) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 15:
=={{header|11l}}==
<
{{out}}
<pre>
Line 24:
{{trans|REXX}}
The program uses two ASSIST macro (XDECO,XPRNT) to keep the code as short as possible.
<
DOW CSECT
USING DOW,R15 base register
Line 66:
PG DS CL12 buffer
YREGS
END DOW</
{{out}}
<pre style="height:16ex"> 2011
Line 87:
=={{header|ABAP}}==
<
data: lv_start type i value 2007,
lv_n type i value 114,
Line 111:
endif.
enddo.
</syntaxhighlight>
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 136:
=={{header|Action!}}==
Action! does not have a standard library providing a day of week function, therefore an adaptation of [https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto.27s_methods Sakamoto's method] to determine the day of week for a given date using integer arithmetic is used.
<syntaxhighlight lang="action!">
Byte FUNC DayOfWeek(BYTE day, month CARD year BYTE century)
CARD weekday
Line 166:
OD
RETURN
</syntaxhighlight>
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 190:
=={{header|Ada}}==
<
with Ada.Text_IO; use Ada.Text_IO;
Line 200:
end if;
end loop;
end Yuletide;</
{{out}}
<pre style="height:30ex;overflow:scroll">
Line 228:
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
<
INT sun=0 # , mon=1, tue=2, wed=3, thu=4, fri=5, sat=6 #;
Line 250:
new line(stand out)
)
</syntaxhighlight>
{{out}}
<pre>
Line 258:
=={{header|ALGOL W}}==
{{Trans|Fortran}}
<
integer procedure Day_of_week ( integer value d, m, y );
begin
Line 278:
if day = 1 then writeon( I_W := 5, S_W := 0, year );
end for_year
end.</
{{out}}
<pre>
Line 285:
=={{header|ALGOL-M}}==
<
BEGIN
Line 326:
END
</syntaxhighlight>
{{out}}
<pre>
Line 349:
</pre>
=={{header|APL}}==
<
⎕IO ← 0 ⍝ Indices are 0-based
y ← 2008 + ⍳114 ⍝ Years from 2008 to 2121
Line 356:
zeller ← { 7 | +/ (((1↑⍴⍵),6)⍴1 1 1 1 ¯1 1) × ⌊(((⍴⍵)⍴1 13 1)×⍵+(⍴⍵)⍴0 1 0)[;0 1 2 2 2 2]÷((1↑⍴⍵),6)⍴1 5 1 4 100 400 }
result ← (1 = zeller 25,[1]12,[0.5]y) / y
</syntaxhighlight>
{{out}}
<pre>
Line 364:
=={{header|AppleScript}}==
<
set Christmas to (current date)
set month of Christmas to December
Line 372:
if weekday of Christmas is Sunday then set end of ChristmasSundays to |year|
end repeat
ChristmasSundays</
Or, composing generic functions:
<
-- xmasIsSunday :: Int -> Bool
on xmasIsSunday(y)
Line 434:
end script
end if
end mReturn</
{{Out}}
<
2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118}</
=={{header|Arc}}==
<
(= day-names '(Sunday Monday Tuesday Wednesday Thursday Friday Saturday))
(= get-weekday-num (fn (year month day)
Line 449:
7)))
(= get-weekday-name (fn (weekday-num) (day-names weekday-num)))
</syntaxhighlight>
<b>test:</b>
<
(when (is 0 (get-weekday-num i 12 25))
(prn i)))
Line 473:
2118
</syntaxhighlight>
=={{header|Arturo}}==
<
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]</
{{out}}
Line 486:
=={{header|AutoHotkey}}==
<
stop = 2121
Line 495:
year++
}
MsgBox,% out</
=={{header|AutoIt}}==
<
Const $iSunday = 1
For $iYear = 2008 To 2121 Step 1
Line 504:
ConsoleWrite(StringFormat($iYear & "\n"))
EndIf
Next</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f DAY_OF_THE_WEEK.AWK
# runtime does not support years > 2037 on my 32-bit Windows XP O/S
Line 517:
}
}
</syntaxhighlight>
=={{header|BASIC}}==
Line 524:
This program needs the modulo function because there is a bug in the built in modulo function.
<
Declare Function wd(m As Double, d As Double, y As Double) As Integer
Line 568:
Dec 25, 2107
Dec 25, 2112
Dec 25, 2118</
==={{header|Applesoft BASIC}}===
{{trans|Commodore BASIC}}
<
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</
==={{header|Atari BASIC}}===
{{trans|Commodore BASIC}}
<
110 PRINT CHR$(125);"SUNDAY CHRISTMASES 2008-2121:":PRINT
120 FOR Y=2008 TO 2121
Line 593:
210 PRINT
220 NEXT Y
230 IF FOUND THEN PRINT</
{{Out}}
Line 606:
==={{header|BaCon}}===
<
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</
{{out}}
Line 637:
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.
<
110 REM MODULO FUNCTION (USES CALLER'S N AS DIVIDEND)
120 DEF FNNM(D) = N - D * INT(N/D)
Line 652:
230 : IF FNXS(Y) THEN PRINT Y,:REM PRINT YEARS IN COLUMNS
240 NEXT Y
250 PRINT</
{{Out}}
Line 664:
==={{header|FreeBASIC}}===
<
' compile with: fbc -s console
Line 687:
Print : Print "hit any key to end program"
Sleep
End</
{{out}}
<pre>Dec 25 2011
Line 706:
Dec 25 2112
Dec 25 2118</pre>
<
' Weekday And DateSerial only works with #Include "vbcompat.bi"
' compile with: fbc -s console
Line 722:
Print : Print "hit any key to end program"
Sleep
End</
{{out}}
<pre>25-12-2011
Line 743:
==={{header|GW-BASIC}}===
<
20 D = 25
30 FOR Y = 2007 TO 2122
Line 757:
150 Z = Z + D + INT((153*M + 8)/5)
160 Z = Z MOD 7
170 RETURN</
==={{header|IS-BASIC}}===
<
110 PRINT "The years between 2008 and 2121 will the 25th of December be a Sunday:"
120 FOR Y=2008 TO 2121
Line 769:
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</
==={{header|Minimal BASIC}}===
<
10 REM Find years with Sunday Christmas
20 LET F = 2008
Line 787:
130 PRINT
140 END
</syntaxhighlight>
==={{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.
<
20 LET D=25
30 FOR Y=2008 TO 2121
Line 804:
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</
{{out}}
<pre>2011
Line 831:
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
<
AUTO 100,10
Line 850:
ctrl+space
</syntaxhighlight>
{{out}}
<pre>2011
Line 871:
==={{header|Tiny BASIC}}===
<
LET Y = 2007
LET M = 12
Line 889:
LET Z = Z + D + (153*M + 8)/5
LET Z = Z - 7*(Z/7)
RETURN</
{{out}}
<pre>2011
Line 910:
=={{header|Batch File}}==
<
:: Batch File Implementation
:: Question: In what years between 2008 and 2121 will the 25th of December be a Sunday?
Line 930:
)
pause
exit /b 0</
{{out}}
<pre>Dec 25, 2011 is a Sunday.
Line 953:
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
FOR year% = 2008 TO 2121
Line 959:
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT</
=={{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.
<
/*
Line 985:
if (w(y, 12, 25) == 0) y
}
quit</
=={{header|BCPL}}==
<
let weekday(y, m, d) =
Line 999:
for year = 2008 to 2121
if weekday(year, 12, 25) = 0
do writef("%N*N", year)</
{{out}}
<pre>2011
Line 1,022:
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.
<
@_^#`"y": +1$<_v#%7+1+/*:*<
>:#,_>$:.55+,^ >0" ,52 ceD"</
{{out}}
Line 1,047:
=={{header|Bracmat}}==
{{trans|C}}
<
( wday
= year month day adjustment mm yy
Line 1,073:
& 1+!y:?y
)
& done;</
{{out}}
<pre>2011-12-25
Line 1,096:
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.
<
/* Calculate day of week in proleptic Gregorian calendar. Sunday == 0. */
Line 1,119:
return 0;
}</
=={{header|C sharp|C#}}==
<
class Program
Line 1,137:
}
}
}</
Using LINQ:
<
using System.Linq;
Line 1,154:
foreach (string day in days) Console.WriteLine(day);
}
}</
<
using System.Linq;
Line 1,167:
.ForEach(ent => Console.WriteLine(ent.ToString("dd MMM yyyy")));
}
}</
{{out}}
<pre style="height:20ex;overflow:scroll">25 Dec 2011
Line 1,188:
=={{header|C++}}==
<
#include <iostream>
Line 1,205:
std::cout << "\n" ;
return 0 ;
}</
{{out}}
<pre>
Line 1,231:
Utilizing Java interop
<
(import '(java.util GregorianCalendar))
(defn yuletide [start end]
Line 1,239:
(yuletide 2008 2121)
</syntaxhighlight>
<pre>(2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</pre>
=={{header|CLU}}==
<
y: int := d.year
m: int := d.month
Line 1,263:
end
end
end start_up</
{{out}}
<pre>2011
Line 1,285:
=={{header|COBOL}}==
Using Date Intrinsic Functions
<syntaxhighlight lang="cobol">
program-id. dec25.
data division.
Line 1,308:
.
end program dec25.
</syntaxhighlight>
{{out}}
<pre style="height:20ex;overflow:scroll">
Line 1,332:
Without Date Intrinsic Functions
<syntaxhighlight lang="cobol">
identification division.
program-id. dowtest.
Line 1,401:
.
end program todow.
</syntaxhighlight>
{{out}}
<pre style="height:20ex;overflow:scroll">
Line 1,424:
=={{header|CoffeeScript}}==
<
sunday = 0
for year in [2008..2121]
xmas = new Date year, december, 25
console.log year if xmas.getDay() is sunday</
{{out}}
<pre style="height:20ex;overflow:scroll">
Line 1,451:
=={{header|ColdFusion}}==
<syntaxhighlight lang="coldfusion">
<cfloop from = "2008" to = "2121" index = "i">
<cfset myDate = createDate(i, 12, 25) />
Line 1,458:
</cfif>
</cfloop>
</syntaxhighlight>
=={{header|Common Lisp}}==
<
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
Line 1,467:
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)</
<
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)</
=={{header|Component Pascal}}==
{{Works with|BlackBox Component Builder}}
<
MODULE DayOfWeek;
IMPORT DevCommanders, TextMappers, Dates, StdLog;
Line 1,514:
END DayOfWeek.
</syntaxhighlight>
Execute: ^Q DayOfWeek.Do 2008 2121~
{{out}}
Line 1,538:
=={{header|Cowgol}}==
<
sub weekday(year: uint16, month: uint8, day: uint8): (wd: uint8) is
Line 1,561:
end if;
year := year + 1;
end loop;</
{{out}}
<pre>2011
Line 1,583:
=={{header|D}}==
<
import std.stdio, std.range, std.algorithm, std.datetime;
Line 1,589:
iota(2008, 2122)
.filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun));
}</
{{out}}
<pre>Christmas comes on a Sunday in the years:
Line 1,596:
=={{header|Delphi}}==
{{libheader|sysutils}} always in uses clause in Delphi
<
var
i: integer;
Line 1,615:
//GUI
form1.label1.caption := outputyears;
end;</
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,625:
=={{header|Draco}}==
<
word c;
if m<3 then
Line 1,645:
fi
od
corp</
{{out}}
<pre>2011
Line 1,666:
=={{header|ECL}}==
<
IMPORT STD;
Line 1,705:
2118
*/
</syntaxhighlight>
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|Elixir}}==
{{works with|Elixir|1.4}}
<
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December #{year} is sunday"
end)</
{{out}}
Line 1,737:
=={{header|Emacs Lisp}}==
<
(defun sunday-p (y)
Line 1,747:
(seq-filter #'sunday-p (number-sequence a b)))
(print (xmas-sunday 2008 2121))</
{{output}}
<pre>(2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</pre>
Line 1,753:
=={{header|Erlang}}==
<
-module(yuletide).
-export([main/0, sunday_years/2]).
Line 1,764:
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.</
{{out}}
<pre>
Line 1,787:
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
PROGRAM DAY_OF_THE_WEEK
Line 1,817:
GET(K$)
END PROGRAM
</syntaxhighlight>
{{out}}
<pre>Dec 25, 2011
Line 1,839:
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">
--Day of the week task from Rosetta Code wiki
--User:Lnettnay
Line 1,855:
end if
end for
</syntaxhighlight>
{{out}}
<pre>
Line 1,878:
=={{header|F_Sharp|F#}}==
<
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"</
{{out}}
<pre>[2011; 2016; 2022; 2033; 2039; 2044; 2050; 2061; 2067; 2072; 2078; 2089; 2095;
Line 1,888:
=={{header|Factor}}==
<
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .</
=={{header|FBSL}}==
<
'In what years between 2008 and 2121 will the 25th of December be a Sunday?
Line 1,904:
next
PAUSE
</syntaxhighlight>
=={{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.
<
\ Zeller's Congruence
: weekday ( d m y -- wd) \ 1 mon..7 sun
Line 1,926:
7 = if i . then
loop cr ;
</syntaxhighlight>
<
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>
To show year-2100 problems with SwiftForth's provided Modified Julian Day support:
<
." December 25 is Sunday in "
2122 2008 do
Line 1,945:
cr yuletide
December 25 is Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2100 2106 2117</
In [[4tH]] a library is available which provides the right answer:
<
: yuletide
Line 1,958:
loop cr ;
cr yuletide</
The code is derived from "Collected Algorithms from ACM", Volume 1 Algorithms 1-220.
Line 1,965:
{{works with|Fortran|90 and later}}
Based on Forth example
<
IMPLICIT NONE
Line 1,994:
END FUNCTION Day_of_week
END PROGRAM YULETIDE</
{{out}}
<pre>
Line 2,009:
=={{header|Frink}}==
<
if (parseDate["$y-12-25"] -> ### u ###) == "7"
println[y]</
{{out}}
Line 2,035:
=={{header|FutureBasic}}==
<
long y
Line 2,058:
next
HandleEvents</
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=b9b4e9a871e96ea6f1db467fa23669fe Click this link to run this code]'''
<
Dim siCount As Short
Line 2,070:
Next
End</
Output:
<pre>
Line 2,093:
=={{header|GAP}}==
<
# [ 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118 ]
Line 2,115:
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 ]</
=={{header|Go}}==
<
import "fmt"
Line 2,130:
}
}
}</
{{out}}
<pre>
Line 2,155:
Solution:
<
Test program:
<syntaxhighlight lang
{{out}}
Line 2,165:
=={{header|Haskell}}==
Using the time library:
<
import Data.Time.Calendar.WeekDate (toWeekDate)
Line 2,184:
| year <- [2008 .. 2121],
isXmasSunday year
]</
{{out}}
<pre>Sunday 25 December 2011
Line 2,205:
The built-in System.Time module can overflow at the Unix epoch in 2038:
<
isXmasSunday :: Int -> Bool
Line 2,233:
[ "25 December " ++ show year ++ " is Sunday"
| year <- [2008 .. 2121]
, isXmasSunday year ]</
{{out}} on 32-bit machine:
<pre>
Line 2,263:
=={{header|HicEst}}==
<
TIME(Year=year, MOnth=12, Day=25, TO, WeekDay=weekday)
IF( weekday == 7) WRITE(StatusBar) year
ENDDO
END</
<pre>No anomalies detected for the first million years :-)
Dec 25 = Sunday in
Line 2,277:
=={{header|Icon}} and {{header|Unicon}}==
<
procedure main()
writes("December 25th is a Sunday in: ")
every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ")
end</
Line 2,288:
[http://www.cs.arizona.edu/icon/library/src/procs/datetime.icn datetime provides dayoweek]
<
static d_code, c_code, m_code, ml_code, y, C, M, Y
Line 2,330:
return d_code[(C + Y + M + day) % 7 + 1]
end</
{{out}}
Line 2,336:
=={{header|J}}==
<
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</
=={{header|Java}}==
<
import java.util.Date;
import java.util.GregorianCalendar;
Line 2,356:
}
}
}</
{{out}}
<pre>Sun Dec 25 00:00:00 CST 2011
Line 2,380:
===ES5===
====Iteration====
<
var xmas = new Date(year, 11, 25)
if ( xmas.getDay() === 0 )
console.log(year)
}</
{{out}}
<pre>2011
Line 2,406:
====Functional composition====
<
'use strict';
Line 2,426:
.filter(isXmasSunday);
})();</
{{Out}}
Line 2,433:
===ES6===
<
"use strict";
Line 2,463:
// MAIN ---
return main();
})();</
{{Out}}
<
=={{header|jq}}==
<
# year, month and day as integers in the conventional way.
# If iso == "iso" or "ISO", then emit an integer in 1 -- 7 where
Line 2,485:
| if iso == "iso" or iso == "ISO" then 1 + ((. + 5) % 7)
else . % 7
end;</
'''The task''':
<
# readily be presented on a single line:
[range(2008; 2122) | select( day_of_week(.;12;25;0) == 1 )]</
{{out}}
$ jq -n -c -f zeller.jq
Line 2,497:
Jsi does not yet implement the Javascript ''Date'' object. ''strftime' and ''strptime'' functions are used here instead.
<
for (var year = 2008; year <= 2121; year++) {
var xmas = strptime(year + '/12/25', '%Y/%m/%d');
Line 2,524:
2118
=!EXPECTEND!=
*/</
{{out}}
Line 2,531:
=={{header|Julia}}==
<
lo, hi = 2008, 2121
Line 2,540:
println("Years from $lo to $hi having Christmas on Sunday: ")
foreach(println, year.(xmas))</
{{out}}
Line 2,563:
=={{header|K}}==
<
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>
=={{header|Kotlin}}==
<
import java.util.*
Line 2,580:
calendar.add(Calendar.YEAR, 1)
}
}</
{{out}}
Line 2,606:
=={{header|Lasso}}==
<
local(tDate = date('12/25/' + loop_count))
#tDate->dayOfWeek == 1 ? '\r' + #tDate->format('%D') + ' is a Sunday'
^}</
{{out}}
Line 2,631:
=={{header|Liberty BASIC}}==
<
for year = 2008 to 2121
dateString$="12/25/";year
Line 2,644:
print count; " years when Christmas Day falls on a Sunday"
end</
=={{header|Lingo}}==
<
refDateObj = date(1905,1,2)
repeat with year = 2008 to 2121
Line 2,653:
dayOfWeek = ((dateObj - refDateObj) mod 7)+1 -- 1=Monday..7=Sunday
if dayOfWeek=7 then put year
end repeat</
{{out}}
<pre>
Line 2,677:
=={{header|LiveCode}}==
<
convert the long date to dateitems
put it into xmasDay
Line 2,689:
if the last char of xmasYear is comma then delete the last char of xmasYear
return xmasYear
end xmasSunday</
=={{header|Logo}}==
<
to leap? :year
output (and
Line 2,725:
; Put it all together to answer the question posed in the problem
print filter [sunday? ? 12 25] iseq 2008 2121
bye</
{{Out}}
Line 2,733:
'''Library:''' [http://luaforge.net/projects/date/ LuaDate]
<
for year=2008,2121 do
Line 2,739:
print(year)
end
end</
{{out}}
Line 2,764:
=== Without external modules ===
Same output as above
<
for year = 2008, 2121 do
dTab.year = year
Line 2,770:
print(year)
end
end</
=={{header|M2000 Interpreter}}==
Str$( number, format$) use Visual Basic 6 format
<syntaxhighlight lang="m2000 interpreter">
Print "December 25 is a Sunday in:"
For Year=2008 to 2121 {
Line 2,790:
</syntaxhighlight>
{{out}}
<pre>
Line 2,813:
=={{header|M4}}==
<
define(`for',
Line 2,831:
for(`yr',2008,2121,
`ifelse(eval(julianxmas(yr)%7==6),1,`yr ')')</
{{out}}
Line 2,840:
=={{header|Maple}}==
<
local i, dt;
for i from 2008 to 2121 by 1 do
Line 2,850:
end proc;
xmas();</
{{Out|Output}}
Line 2,875:
Or simply:
<
{{out}}
Line 2,881:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
gives back:
<
=={{header|MATLAB}} / {{header|Octave}}==
<
t = t(strmatch('Sunday', datestr(t,'dddd')), :);
datestr(t,'yyyy')
</syntaxhighlight>
Line 2,915:
=={{header|Maxima}}==
<
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,924:
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] */</
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">П9 7 П7 1 П8 НОП ИП8 2 2 -
1 0 / [x] П6 ИП9 + 1 8 9
9 - 3 6 5 , 2 5 * [x]
Line 2,933:
0 , 5 9 * [x] + 2 9 +
ИП7 + П4 ИП4 7 / [x] 7 * -
x=0 64 ИП9 С/П ИП9 1 + П9 БП 06</
''Input:'' РX: starting year.
Line 2,945:
Consequently, it suffers from the same problem as C.
<
IMPORT IO, Fmt, Date, Time;
Line 2,972:
END;
END;
END Yule.</
{{out}}
Line 2,985:
=={{header|MUMPS}}==
{{libheader|VA Kernel|22.0}}
<syntaxhighlight lang="mumps">
DOWHOLIDAY
;In what years between 2008 and 2121 will December 25 be a Sunday?
Line 3,005:
KILL BDT,EDT,CHECK,CHKFOR,LIST,I,X,Y
QUIT
</
The following years have Christmas on a Sunday: 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
Line 3,011:
=={{header|Nanoquery}}==
<
// loop through the years 2008 through 2121
Line 3,018:
println "In " + year + ", December 25th is a Sunday."
end if
end for</
=={{header|NetRexx}}==
<
options replace format comments java crossref savelog symbols nobinary
Line 3,039:
return
</syntaxhighlight>
{{out}}
<pre>
Line 3,047:
===Comparison of Some Common Day-of-Week Algorithms===
The following program exercises some common "Day-0f-Week" algorithms to confirm they all arrive at the same result.
<
options replace format comments java crossref savelog symbols nobinary
Line 3,238:
method modulo(N = int, D = int) inheritable static binary returns int
return (D + (N // D)) // D
</syntaxhighlight>
{{out}}
<pre>
Line 3,252:
=={{header|Nim}}==
<
for year in 2008..2121:
if getDayOfWeek(25, mDec, year) == dSun:
stdout.write year, ' '
echo ""</
{{out}}
Line 3,264:
=={{header|Oberon-2}}==
{{works with|oo2c version 2}}
<
MODULE DayOfWeek;
IMPORT NPCT:Dates, Out;
Line 3,278:
END
END DayOfWeek.
</syntaxhighlight>
{{out}}
<pre>
Line 3,300:
</pre>
{{works with|AOS}}
<syntaxhighlight lang="oberon2">
MODULE DaysOfWeek; (** AUTHOR ""; PURPOSE ""; *)
Line 3,320:
END DaysOfWeek.
</syntaxhighlight>
{{out}}
<pre>
Line 3,347:
{{works with|Cocoa}}
<
int main()
Line 3,368:
}
return 0;
}</
{{out}}
Line 3,393:
=={{header|OCaml}}==
{{trans|C}}
<
open Unix
Line 3,412:
raise e
done
with _ -> ()</
{{out}} of a run on a 32 bit machine
Line 3,429:
Unlike the previous example which only uses the OCaml standard library, here with the OCaml Calendar Library we can go until the year 2121:
<
let list_make_seq first last =
Line 3,446:
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</
{{out}}
Line 3,471:
=={{header|Oforth}}==
<
seqFrom(2008, 2121) filter(#[ 12 25 Date newDate dayOfWeek Date.SUNDAY == ]) .</
{{out}}
<pre>
Line 3,480:
=={{header|ooRexx}}==
===Christmas===
<
lastdate = .datetime~new(2121, 12, 25)
Line 3,492:
end
say "Christmas falls on Sunday in the years" resultList~toString("Line", ", ")</
{{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===
<
Parse Arg yyyymmdd
If arg(1)='' |,
Line 3,506:
wd=.Array~of('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')
dt=.DateTime~new(y,m,d)
say yyyymmdd 'is a' wd[dt~weekday]</
{{out}}
<pre>H:\>rexx wd ?
Line 3,515:
=={{header|PARI/GP}}==
<
njd(D) =
{
Line 3,526:
for (y = 2008, 2121, if (njd([y,12,25]) % 7 == 1, print(y)));
</syntaxhighlight>
Output:
Line 3,554:
=={{header|Peloton}}==
<
<@ ITEFORLI3>2121|2008|
<@ LETVARCAP>Christmas Day|25-Dec-<@ SAYVALFOR>...</@></@>
Line 3,562:
</@>
</@>
</@></
English dialect variable-length space-padded opcodes
<
<# iterate foriteration literalstring3>2121|2008|
<# let variable capture>Christmas Day|25-Dec-<# say value foriteration>...</#></#>
Line 3,574:
</#>
</#></
{{out}}
Line 3,597:
=={{header|Perl}}==
<
use Time::Local;
Line 3,612:
}
exit 0;</
{{out}}
Line 3,627:
Using the DateTime module from CPAN:
<
use DateTime;
Line 3,644:
}
exit 0;</
or shorter:
<
use DateTime;
Line 3,656:
}
exit 0;</
{{out}}
<pre>
Line 3,679:
Alternatively in one line using grep (read from right to left):
<
use DateTime;
Line 3,686:
print join " ", grep { DateTime->new(year => $_, month => 12, day => 25)->day_of_week == 7 } (2008 .. 2121);
0;</
{{out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
Line 3,692:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Day_of_the_week.exw</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #0000FF;">}</span>
Line 3,701:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?<span style="color: #000000;">res
<!--</
{{out}}
<pre>
Line 3,709:
=={{header|PHP}}==
<
for($i=2008; $i<2121; $i++)
{
Line 3,718:
}
}
?></
{{out}}
Line 3,742:
=={{header|Picat}}==
<
L = [Year : Year in 2008..2121, dow(Year, 12, 25) == 0],
println(L),
Line 3,755:
end,
R = (Y + Y // 4 - Y // 100 + Y // 400 + T[M] + D) mod 7.
</syntaxhighlight>
{{out}}
Line 3,762:
=={{header|PicoLisp}}==
<
(when (= "Sunday" (day (date Y 12 25)))
(printsp Y) ) )</
{{out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
=={{header|Pike}}==
<
{{out}}
<pre>
Line 3,794:
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
declare i picture '9999';
do i = 2008 to 2121;
Line 3,800:
put skip list ('Christmas day ' || i || ' is a Sunday');
end;
</syntaxhighlight>
==={{header|PL/I-80}}===
<
sunday_christmas:
Line 3,845:
end sunday_christmas;
</syntaxhighlight>
{{out}}
<pre>Christmas will fall on Sunday in these years:
Line 3,868:
=={{header|PowerShell}}==
<
===Find Christmas holiday for any day and/or year===
<syntaxhighlight lang="powershell">
function Get-ChristmasHoliday
{
Line 3,906:
}
}
</syntaxhighlight>
Satisfy the task requirement:
<syntaxhighlight lang="powershell">
2008..2121 | Get-ChristmasHoliday | where DayOfWeek -match Su
</syntaxhighlight>
{{Out}}
<pre>
Line 3,934:
</pre>
Get days off for a random year:
<syntaxhighlight lang="powershell">
Get-ChristmasHoliday -Year (2008..2121 | Get-Random)
</syntaxhighlight>
{{Out}}
<pre>
Line 3,944:
</pre>
Get days off for the current year using the '''Year''' property returned by <code>Get-Date</code>:
<syntaxhighlight lang="powershell">
(Get-Date | Get-ChristmasHoliday).DaysOff
</syntaxhighlight>
{{Out}}
<pre>
Line 3,956:
</pre>
Get days off for the current year as <code>[DateTime]</code> objects:
<syntaxhighlight lang="powershell">
(Get-Date | Get-ChristmasHoliday).DaysOff | Get-Date
</syntaxhighlight>
{{Out}}
<pre>
Line 3,970:
=={{header|Prolog}}==
Works with SWI-Prolog;
<
christmas_days_falling_on_sunday(2011, 2121, SundayList),
writeln(SundayList).
Line 3,982:
day_of_the_week(Date, DayOfTheWeek),
DayOfTheWeek == 7.
</syntaxhighlight>
{{out}}
<pre>?- main.
Line 3,990:
=={{header|PureBasic}}==
PureBasic's internal Date() is limited between 1970-01-01 00:00:00 and 2038-01-19 03:14:07
<
If DayOfWeek(Date(i,12,25,0,0,0))=0
PrintN(Str(i))
EndIf
Next</
=={{header|Python}}==
<
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]</
{{out}}
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
Line 4,008:
Or, in terms of datetime:
{{Works with|Python|3.7}}
<
from datetime import date
Line 4,078:
# MAIN --
if __name__ == '__main__':
main()</
{{Out}}
<pre>Years between 2008 and 2121 with 25 Dec on a Sunday:
Line 4,106:
Using Tomohiko Sakamoto's algorithm.
<
dup 4 / over +
over 100 / -
Line 4,119:
2121 1+ 2008 - times
[ 25 12 i^ 2008 + dayofweek
0 = if [ i^ 2008 + echo sp ] ] </
{{out}}
Line 4,127:
=={{header|R}}==
<
xmas <- as.POSIXlt(paste0(years, '/12/25'))
years[xmas$wday==0]
Line 4,147:
# Under MS Windows, write instead
Sys.setlocale("LC_ALL", "English")</
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
Line 4,161:
(for ([y (in-range 2008 2121)] #:when (xmas-on-sunday? y))
(displayln y))
</syntaxhighlight>
=={{header|Raku}}==
Line 4,170:
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"
=={{header|REBOL}}==
<
Title: "Yuletide Holiday"
URL: http://rosettacode.org/wiki/Yuletide_Holiday
Line 4,181:
d: to-date reduce [y 12 25]
if 7 = d/weekday [prin [y ""]]
]</
{{out}}
Line 4,187:
=={{header|Red}}==
<
repeat yy 114 [
d: to-date reduce [25 12 (2007 + yy )]
Line 4,202:
d/year: d/year + 1
]
</syntaxhighlight>
{{out}}<pre>25-Dec-2011
25-Dec-2016
Line 4,244:
===using DATE weekday===
The extended DATE parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
<
if date('w', year"1225", 's') == 'Sunday' then say year
end /*year*/</
{{out|output}}
<pre>
Line 4,270:
===using DATE base===
The extended DATE parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
<
if date('b', year"1225", 's') // 7 == 6 then say year
end /*year*/</
{{out|output|text= is identical to the 1<sup>st</sup> REXX version.}} <br><br>
Line 4,283:
Language note: the DATE built-in function always returns the day-of-week in English, no matter what the native language is in effect.
<
parse arg start finish . /*get the START and FINISH years. */
if start=='' | start=="," then start=2008 /*Not specified? Then use the default.*/
Line 4,298:
say 'December 25th,' y "falls on a Sunday."
end /*y*/
/*stick a fork in it, we're all done. */</
{{out|output|text= when using the default inputs:}}
<pre>
Line 4,322:
===old school DOW ===
This DOW (day-of-week) version will work with any version of a REXX interpreter.
<
parse arg start finish . /*get the START and FINISH years. */
if start=='' | start=="," then start=2008 /*Not specified? Then use the default.*/
Line 4,334:
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*/</
{{out|output|text= when using the default input:}}
<pre>
Line 4,357:
=={{header|Ring}}==
<
for n = 2008 to 2121
if n < 2100 leap = n - 1900 else leap = n - 1904 ok
Line 4,363:
if m = 4 see "25 Dec " + n + nl ok
next
</syntaxhighlight>
=={{header|Ruby}}==
<
(2008..2121).each {|year| puts "25 Dec #{year}" if Date.new(year, 12, 25).sunday? }</
{{out}}
<pre>
Line 4,391:
Or using the Time class
<
{{output}}
<pre>
Line 4,416:
=={{header|Run BASIC}}==
<
if val(date$("12-25-";year)) mod 7 = 5 then print "For ";year;"xmas is Sunday"
next year</
For 2011 xmas is Sunday
For 2016 xmas is Sunday
Line 4,439:
=={{header|Rust}}==
<
use chrono::prelude::*;
Line 4,446:
let years = (2008..2121).filter(|&y| Local.ymd(y, 12, 25).weekday() == Weekday::Sun).collect::<Vec<i32>>();
println!("Years = {:?}", years);
}</
Output:
Line 4,453:
=={{header|S-BASIC}}==
<syntaxhighlight lang="basic">
$constant SUNDAY = 0
Line 4,487:
next year
end
</syntaxhighlight>
{{out}}
<pre>Christmas will fall on a Sunday in
Line 4,509:
=={{header|SAS}}==
<
do y=2008 to 2121;
a=mdy(12,25,y);
Line 4,517:
/* 2011 2016 2022 2033 2039 2044 2050 2061 2067
2072 2078 2089 2095 2101 2107 2112 2118 */</
=={{header|Scala}}==
{{libheader|Scala}}
===JDK (discouraged) ===
<
import Calendar.{ DAY_OF_WEEK, DECEMBER, SUNDAY }
Line 4,539:
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</
===JDK >= 8 (recommended)===
====Naive programming====
<
object DayOfTheWeek1 extends App {
Line 4,554:
s"${yuletide.count(p => true)} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</
====Idiomatic programming====
<
object DayOfTheWeek1 extends App {
Line 4,571:
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</
====Tail recursion====
<
import scala.annotation.tailrec
Line 4,597:
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</
{{out | Output of all solutions }}
<pre>Years between 2008 and 2121 including when Christmas is observed on Sunday:
Line 4,603:
=={{header|Scheme}}==
<
(if (< month 3)
(begin (set! month (+ month 12)) (set! year (- year 1))))
Line 4,621:
(task)
; (2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</
=={{header|Seed7}}==
Line 4,627:
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.
<
include "time.s7i";
Line 4,639:
end if;
end for;
end func;</
{{out}}
<pre>
Line 4,662:
=={{header|SenseTalk}}==
<
repeat with year = 2008 to 2121
Line 4,669:
put "Christmas in " & year & " falls on a Sunday"
end if
end repeat</
{{out}}
<pre>
Line 4,693:
=={{header|Sidef}}==
{{trans|Perl}}
<
for year in (2008 .. 2121) {
Line 4,701:
say "25 Dec #{year} is Sunday"
}
}</
{{out}}
<pre>
Line 4,724:
=={{header|Simula}}==
{{trans|Sinclair ZX81 BASIC}}
<
INTEGER M,D,Y;
M := 12;
Line 4,740:
END;
END;
END.</
{{out}}
<pre>2011
Line 4,761:
=={{header|Smalltalk}}==
<
date := Date newDay: 25 monthIndex: 12 year: year.
date dayName = #Sunday
ifTrue: [ date displayNl ]
]</
{{out}}
Line 4,790:
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.)
<
from (
select add_months(date '2008-12-25', 12 * (level - 1)) as dt
Line 4,798:
where to_char(dt, 'Dy', 'nls_date_language=English') = 'Sun'
order by 1
;</
Line 4,827:
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):
<
=={{header|Standard ML}}==
<
fun yearsOfSundayXmas(fromYear, toYear) =
if fromYear>toYear then
Line 4,848:
else
yearsOfSundayXmas(fromYear+1, toYear)
end;</
{{out}}
Line 4,873:
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.
<
sca n=2121-2008+1
set obs `=n'
Line 4,899:
| 2112 |
| 2118 |
+------+</
=== Mata ===
<
select(year,dow(mdy(12,25,year)):==0)</
=={{header|Suneido}}==
<
while (year <= 2121)
{
Line 4,913:
Print(year)
++year
}</
{{out}}
<pre>2011
Line 4,934:
=={{header|Swift}}==
<
var year=2008
Line 4,949:
}
year++
}</
{{out}}
<pre>2011
Line 4,971:
=={{header|Tcl}}==
{{works with|Tcl|8.5}}
<
for {set y 2008} {$y <= 2121} {incr y} {
Line 4,977:
puts "xmas $y is a sunday"
}
}</
{{out}}
<pre>xmas 2011 is a sunday
Line 4,999:
=={{header|TI-83 BASIC}}==
'''Works with''' TI-84+/SE only
<
:For(A,2008,2121
:If dayofWk(A,12,25)=1
:Disp A
:End
</syntaxhighlight>
{{out}}
<pre>2011
Line 5,026:
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
PRINT "25th of December will be a Sunday in the following years: "
Line 5,033:
IF (dayofweek==7) PRINT year
ENDLOOP
</syntaxhighlight>
{{out}}
<pre>
Line 5,058:
== {{header|TypeScript}} ==
{{trans|Minimal BASIC}}
<
// Find years with Sunday Christmas
var f = 2008;
Line 5,069:
}
process.stdout.write("\n");
</syntaxhighlight>
{{out}}
<pre>
Line 5,083:
{{works with|bash}}
<
for (( i=2008; i<=2121; ++i ))
Line 5,090:
done |grep Sun
exit 0</
The first lines of output (from a GNU/Linux system with 32bit time_t, date version 6.9) are
<
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'</
I.e., starting from year 2038, the <tt>date</tt> command (which uses the glibc library, at least on GNU systems), is not able to recognise the date as a valid one!
Line 5,104:
''Different machine/OS version (64 bit time_t):''
This is the same command run on RedHat Linux.
<
date (coreutils) 5.2.1
Written by David MacKenzie.
Line 5,131:
Sun Dec 25 00:00:00 GMT 2112
Sun Dec 25 00:00:00 GMT 2118
bash-3.00$</
===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.
<
===With Unix cal===
Line 5,154:
{{works with|Bourne Shell}}
<
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</
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===
<
for (( year = 2010; year <= 2121; year++ ));
if [[ $(strftime '%A' $(strftime -r '%F' $year-12-25)) == Sunday ]] print $year</
If the system has 32-bit time, this script will malfunction for years >= 2038; it will print no year from 2038 to 2121 (unless today is Sunday, then it prints every year from 2038 to 2121). This happens because ''strftime -r '%F' $year-12-25'' yields -1 for an out-of-range date, and ''strftime '%A' -1'' yields name of today.
Line 5,182:
date with the weekday included. The output is then filtered for Sundays.
<
#import nat
#import stt
Line 5,190:
#show+
sunday_years = ~&zS sep` * =]'Sun'*~ christmases</
{{out}}
<pre>2011
Line 5,211:
=={{header|VBA}}==
<
Sub MainDayOfTheWeek()
Line 5,223:
Next
XmasSunday = Mid(temp, 2)
End Function</
{{Out}}
Line 5,229:
=={{header|VBScript}}==
<
If Weekday(DateSerial(year, 12, 25)) = 1 Then
WScript.Echo year
End If
Next</
{{Out}}
Line 5,257:
=={{header|Vedit macro language}}==
<
for (#3 = 2008; #3 < 2122; #3++) {
Reg_Set(10, "12/25/")
Line 5,264:
Num_Ins(#3, NOCR)
}
}</
{{out}}
Line 5,272:
=={{header|Visual Objects}}==
<
local i as dword
Line 5,280:
endif
next i
</syntaxhighlight>
{{out}}
Line 5,289:
=={{header|Vlang}}==
Updated for Vlang version 0.2.2
<
fn main() {
Line 5,298:
}
}
}</
{{out}}
Line 5,324:
{{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.
<
1010 R=!
1020 N=M
Line 5,345:
2080 Y=Y+1
2090 #=Y<2121*2040
2100 ?=""</
{{out}}
<pre>
Line 5,352:
=={{header|Wortel}}==
<
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}}
<
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)
}</
{{out}}
Line 5,391:
the Gregorian calendar, from 1583 onward. It's based on Zeller's Congruence.
<
func WeekDay(Year, Month, Day); \Return day of week (0=Sat 1=Sun..6=Fri)
Line 5,404:
if WeekDay(Year, 12, 25) = 1 then \25th of December is a Sunday
[IntOut(0, Year); CrLf(0)];
]</
{{out}}
Line 5,429:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<
If m < 3 Then // If m = 1 Or m = 2 Then
m = m + 12
Line 5,443:
Print "Dec 25 ", yr
EndIf
Next</
=={{header|zkl}}==
ISO dates, monday is 1, sunday is 7
<
foreach y in ([2008..2121]){
if (D.Sunday==D.weekDay(y,12,25)) println(y)
}</
Or, in a more functional manner:
<
[2008..2121].filter(fcn(y){ D.Sunday==D.weekDay(y,12,25) }).println()</
{{out}}
<pre>
Line 5,476:
=={{header|zonnon}}==
<
module Main;
(*Access to Mono System package *)
Line 5,488:
System.Console.WriteLine(now.DayOfWeek);
end Main.
</syntaxhighlight>
{{Out}}
<pre>
Line 5,496:
=={{header|ZX Spectrum Basic}}==
{{trans|BASIC}}
<
20 FOR y=2008 TO 2121
30 LET year=y: LET m=12: LET d=25: GO SUB 1000
Line 5,506:
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</
|