Five weekends: Difference between revisions

→‎{{header|Tcl}}: extra credit
m (→‎{{header|D}}: added extra)
(→‎{{header|Tcl}}: extra credit)
Line 263:
<lang tcl>package require Tcl 8.5
 
set months {}
set years {}
for {set year 1900} {$year <= 2100} {incr year} {
set count [llength $months]
foreach month {Jan Mar May Jul Aug Oct Dec} {
set date [clock scan "$month/01/$year" -format "%b/%d/%Y" -locale en_US]
Line 270 ⟶ 273:
lappend months "$month $year"
}
}
if {$count == [llength $months]} {
lappend years $year
}
}
puts "There are [llength $months] months with five weekends"
puts [join [list {*}[lrange $months 0 4] ... {*}[lrange $months end-4 end]] \n]</lang>
puts "There are [llength $years] years without any five-weekend months"
puts [join $years ", "]</lang>
Output:
<pre>
There are 201 months with five weekends
Mar 1901
Aug 1902
Line 288 ⟶ 296:
Jan 2100
Oct 2100
There are 29 years without any five-weekend months
1900, 1906, 1917, 1923, 1928, 1934, 1945, 1951, 1956, 1962, 1973, 1979, 1984, 1990, 2001, 2007, 2012, 2018, 2029, 2035, 2040, 2046, 2057, 2063, 2068, 2074, 2085, 2091, 2096
</pre>
Anonymous user