Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Five-weekends/Tcl/five-weekends.tcl
Normal file
22
Task/Five-weekends/Tcl/five-weekends.tcl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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]
|
||||
if {[clock format $date -format %u] == 5} {
|
||||
# Month with 31 days that starts on a Friday => has 5 weekends
|
||||
lappend months "$month $year"
|
||||
}
|
||||
}
|
||||
if {$count == [llength $months]} {
|
||||
# No change to number of months; year must've been without
|
||||
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]
|
||||
puts "There are [llength $years] years without any five-weekend months"
|
||||
puts [join $years ","]
|
||||
Loading…
Add table
Add a link
Reference in a new issue