Five weekends: Difference between revisions
→{{header|Ruby}}: Remove nested loop; shortened somewhat.
(added Factor) |
(→{{header|Ruby}}: Remove nested loop; shortened somewhat.) |
||
Line 5,787:
# of the month falls on a Sunday and the month has 31 days.
LONG_MONTHS = [1,3,5,7,8,10,12]
YEARS = (1900.
dates = YEARS.product(LONG_MONTHS).map{|y, m| Date.new(y,m,-1)}.select(&:sunday?)
puts "There are #{dates.size} months with 5 weekends from 1900 to 2100:"
puts dates.first(5).map {
▲puts dates.last(5).map { |d| d.strftime("%b %Y") }
years_with_5w = dates.map(&:year)▼
puts "There are #{
puts
'''Output'''
|