June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,26 +1,21 @@
isdefined(:Date) || using Dates
isweekend(dt::Date) = Dates.dayofweek(dt) ∈ (Dates.Friday, Dates.Saturday, Dates.Sunday)
const wday = Dates.Fri
const lo = 1900
const hi = 2100
const showres = 5
mfive = recur(Date(lo, 1):Month(1):Date(hi, 12)) do m
Dates.daysinmonth(m) == 31 && Dates.dayofweek(m) == wday
function hasfiveweekend(month::Integer, year::Integer)
dmin = Date(year, month, 1)
dmax = dmin + Dates.Day(Dates.daysinmonth(dmin) - 1)
return count(isweekend, dmin:dmax) ≥ 15
end
println("Considering the years from ", lo, " to ", hi, ".\n")
println("There are ", length(mfive), " months having 5 3-day weekends.")
months = collect((y, m) for y in 1900:2100, m in 1:12 if hasfiveweekend(m, y))
println("The first ", showres, " such months are:")
for m in mfive[1:showres]
println(" ", Dates.monthname(m), " ", Dates.year(m))
end
println("Number of months with 5 full-weekends: $(length(months))")
println("First five such months:")
for (y, m) in months[1:5] println(" - $y-$m") end
println("Last five such months:")
for (y, m) in months[end-4:end] println(" - $y-$m") end
println("\nThe last ", showres, " such months are:")
for m in mfive[end-showres+1:end]
println(" ", Dates.monthname(m), " ", Dates.year(m))
end
# extra credit
yrs = getindex.(months, 1)
nyrs = 2100 - 1899 - length(unique(yrs))
print("\nThere are ", length(filter(y -> !(y in year(mfive)), lo:hi)))
println(" years that have no such months.")
println("Number of year with not one 5-full-weekend month: $nyrs")