Created
June 7, 2011 06:46
-
-
Save jonyesno/1011786 to your computer and use it in GitHub Desktop.
More on that 'special' month thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# a rework of https://gist.github.com/612030 which only considered Octobers | |
require 'date' | |
require 'pp' | |
start = 1852 # when Gregorian calendar started | |
finish = Date.today.year | |
special = [] | |
(start .. finish).each do |year| | |
(1 .. 12).each do |month| | |
total = Hash.new { |h,k| h[k] = 0 } # hash of day names and their frequency | |
(Date.new(year, month, 1) .. Date.new(year, month, -1)).each do |day| | |
# Date#wday() == day-of-week. sunday is 0, saturday is 6 | |
# Date::DAYNAMES is a zero-offset array of strings ["Sunday" .. "Saturday"] | |
day_of_week = Date::DAYNAMES[day.wday] | |
total[day_of_week] += 1 | |
end | |
# now see if we think this month is special | |
if total["Friday"] == 5 && | |
total["Saturday"] == 5 && | |
total["Sunday"] == 5 | |
special << "#{year}-#{month}" | |
end | |
end | |
end | |
# fsdo 'special' :) | |
puts "special months:" | |
puts special.join(",") | |
puts "total specials: #{special.length}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check the last one by hand: