June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
17
Task/Five-weekends/Factor/five-weekends.factor
Normal file
17
Task/Five-weekends/Factor/five-weekends.factor
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
USING: calendar calendar.format formatting fry io kernel math
|
||||
sequences ;
|
||||
IN: rosetta-code.five-weekends
|
||||
|
||||
: timestamps>my ( months -- )
|
||||
[ { MONTH bl YYYY nl } formatted 2drop ] each ;
|
||||
|
||||
: month-range ( start-year #months -- seq )
|
||||
'[ _ <year> _ <iota> ] call [ months time+ ] with map ;
|
||||
|
||||
: find-five-weekend-months ( months -- months' )
|
||||
[ [ friday? ] [ days-in-month ] bi 31 = and ] filter ;
|
||||
|
||||
1900 12 201 * month-range find-five-weekend-months
|
||||
[ length "%d five-weekend months found.\n" printf ]
|
||||
[ 5 head timestamps>my "..." print ]
|
||||
[ 5 tail* timestamps>my ] tri
|
||||
|
|
@ -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")
|
||||
|
|
|
|||
17
Task/Five-weekends/Maple/five-weekends.maple
Normal file
17
Task/Five-weekends/Maple/five-weekends.maple
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
five_weekends:= proc()
|
||||
local i, month, count;
|
||||
#Only months with 31 days can possibly satisfy the condition
|
||||
local long_months := [1,3,5,7,8,10,12];
|
||||
local months := ["January","February","March","April","May","June","July","August","September","October","November","December"];
|
||||
count := 0;
|
||||
for i from 1900 to 2100 by 1 do
|
||||
for month in long_months do
|
||||
if Calendar:-DayOfWeek(Date(i, month, 1)) = 6 then
|
||||
printf("%d-%s\n", i, months[month]);
|
||||
count++;
|
||||
end if;
|
||||
end do;
|
||||
end do;
|
||||
printf("%d months have five full weekends.\n", count);
|
||||
end proc;
|
||||
five_weekends();
|
||||
30
Task/Five-weekends/Stata/five-weekends.stata
Normal file
30
Task/Five-weekends/Stata/five-weekends.stata
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
clear
|
||||
set obs `=tm(2101m1)-tm(1900m1)'
|
||||
gen month=tm(1900m1)+_n-1
|
||||
format %tm month
|
||||
gen day=dofm(month)
|
||||
keep if dofm(month+1)-day==31 & dow(day)==5
|
||||
drop day
|
||||
|
||||
count
|
||||
201
|
||||
|
||||
list in f/5, noobs noheader
|
||||
|
||||
+--------+
|
||||
| 1901m3 |
|
||||
| 1902m8 |
|
||||
| 1903m5 |
|
||||
| 1904m1 |
|
||||
| 1904m7 |
|
||||
+--------+
|
||||
|
||||
list in -5/l, noobs noheader
|
||||
|
||||
+---------+
|
||||
| 2097m3 |
|
||||
| 2098m8 |
|
||||
| 2099m5 |
|
||||
| 2100m1 |
|
||||
| 2100m10 |
|
||||
+---------+
|
||||
22
Task/Five-weekends/VBA/five-weekends.vba
Normal file
22
Task/Five-weekends/VBA/five-weekends.vba
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Main()
|
||||
Dim y As Long, m As Long, t As String, cpt As Long, cptm As Long
|
||||
For y = 1900 To 2100
|
||||
t = vbNullString
|
||||
For m = 1 To 12 Step 2
|
||||
If m = 9 Then m = 8
|
||||
If Weekday(DateSerial(y, m, 1)) = vbFriday Then
|
||||
t = t & ", " & m
|
||||
cptm = cptm + 1
|
||||
End If
|
||||
Next
|
||||
If t <> "" Then
|
||||
Debug.Print y & t
|
||||
Else
|
||||
cpt = cpt + 1
|
||||
End If
|
||||
Next
|
||||
Debug.Print "There is " & cptm & " months with five full weekends from the year 1900 through 2100"
|
||||
Debug.Print "There is " & cpt & " years which don't have months with five weekends"
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue