Day of the week: Difference between revisions

No edit summary
Line 1,896:
 
=={{header|Julia}}==
<lang{{works with|Julia>|0.6}}
isdefined(:Date) || using Dates
 
<lang julia>using Base.Dates
lo = 2008
hi = 2121
xmas = Date(lo, 12, 25):Year(1):Date(hi, 12, 25)
 
lo, hi = 2008, 2121
smas = recur(xmas) do y
xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25))
Dates.dayofweek(y) == Dates.Sun
smas = recurfilter!(xmas) do ydt
Dates.dayofweek(ydt) == Dates.SunSunday
end
 
println("Years (from ", $lo, " to ", $hi, ") having Christmas on a Sunday: ")
foreach(println, year.(xmas))</lang>
 
for y in smas
println(" ", Dates.year(y))
end
</lang>
 
This code uses the <code>Dates</code> module, which is being incorporated into Julian's standard library with the current development version (<tt>0.4</tt>). I've used <code>isdefined</code> to make this code good for the current stable version (<tt>0.3</tt>) as well as for future releases. If <code>Dates</code> is not installed on your instance of Julian try <code>Pkg.add("Dates")</code> from the <tt>REPL</tt>.
 
{{out}}
<pre>Years (from 2008 to 2121) having Christmas on a Sunday:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
</pre>
 
=={{header|K}}==
Anonymous user