RosettaCodeData/Task/Long-year/Tcl/long-year.tcl
2023-07-01 13:44:08 -04:00

25 lines
667 B
Tcl

## Reference: https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
proc p {year} {
return [expr {($year + ($year/4) - ($year/100) + ($year/400)) % 7}]
}
proc is_long_year {year} {
return [expr {[p $year] == 4 || [p [expr {$year - 1}]] == 3}]
}
proc print_long_years {from to} {
for {set year $from; set count 0} {$year <= $to} {incr year} {
if {[is_long_year $year]} {
if {$count > 0} {
puts -nonewline [expr {($count % 10 == 0) ? "\n" : " "}]
}
puts -nonewline $year
incr count
}
}
}
puts "Long years between 1800 and 2100:"
print_long_years 1800 2100
puts ""