Skip to content

Instantly share code, notes, and snippets.

@jonyesno
Created June 7, 2011 06:46
Show Gist options
  • Save jonyesno/1011786 to your computer and use it in GitHub Desktop.
Save jonyesno/1011786 to your computer and use it in GitHub Desktop.
More on that 'special' month thing
#!/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}"
@jonyesno
Copy link
Author

jonyesno commented Jun 7, 2011

$ ./day-counter.rb  
special months:
1852-10,1853-7,1854-12,1856-8,1857-5,1858-1,1858-10,1859-7,1861-3,1862-8,1863-5,1864-1,1864-7,1865-12,1867-3,1868-5,1869-1,1869-10,1870-7,1871-12,1872-3,1873-8,1874-5,1875-1,1875-10,1876-12,1878-3,1879-8,1880-10,1881-7,1882-12,1884-8,1885-5,1886-1,1886-10,1887-7,1889-3,1890-8,1891-5,1892-1,1892-7,1893-12,1895-3,1896-5,1897-1,1897-10,1898-7,1899-12,1901-3,1902-8,1903-5,1904-1,1904-7,1905-12,1907-3,1908-5,1909-1,1909-10,1910-7,1911-12,1912-3,1913-8,1914-5,1915-1,1915-10,1916-12,1918-3,1919-8,1920-10,1921-7,1922-12,1924-8,1925-5,1926-1,1926-10,1927-7,1929-3,1930-8,1931-5,1932-1,1932-7,1933-12,1935-3,1936-5,1937-1,1937-10,1938-7,1939-12,1940-3,1941-8,1942-5,1943-1,1943-10,1944-12,1946-3,1947-8,1948-10,1949-7,1950-12,1952-8,1953-5,1954-1,1954-10,1955-7,1957-3,1958-8,1959-5,1960-1,1960-7,1961-12,1963-3,1964-5,1965-1,1965-10,1966-7,1967-12,1968-3,1969-8,1970-5,1971-1,1971-10,1972-12,1974-3,1975-8,1976-10,1977-7,1978-12,1980-8,1981-5,1982-1,1982-10,1983-7,1985-3,1986-8,1987-5,1988-1,1988-7,1989-12,1991-3,1992-5,1993-1,1993-10,1994-7,1995-12,1996-3,1997-8,1998-5,1999-1,1999-10,2000-12,2002-3,2003-8,2004-10,2005-7,2006-12,2008-8,2009-5,2010-1,2010-10,2011-7
total specials: 160

Check the last one by hand:

$ cal 10 2010
    October 2010
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment