Skip to content

Instantly share code, notes, and snippets.

@RajaS
Created October 5, 2012 14:00
Show Gist options
  • Save RajaS/3839944 to your computer and use it in GitHub Desktop.
Save RajaS/3839944 to your computer and use it in GitHub Desktop.
Find how many "moneybag months" there are since 1900
#!/usr/bin/env python
from calendar import monthrange
from datetime import date
def month_has_31(yr, mth):
"""
Does the month have 31 days?
"""
return monthrange(yr, mth)[1] == 31
def is_monday(yr, mth, day):
"""
Is this date a monday
"""
return date(yr, mth, day).weekday() == 0
def main():
moneybags_months = []
# all months from 1900
for yr in range(1900, 2013):
for mth in range(1, 13):
if month_has_31(yr, mth) and is_monday(yr, mth, 1):
moneybags_months.append((yr, mth))
print "Found %s months" %(len(moneybags_months))
print "Moneybags Months"
print "----------------"
for yr, mth in moneybags_months:
print "%2d-%d" %(mth, yr)
if __name__ == "__main__":
main()
# Output ##
###########
# Found 114 months
# Moneybags Months
# ----------------
# 1-1900
# 10-1900
# 7-1901
# 12-1902
# 8-1904
# 5-1905
# 1-1906
# 10-1906
# 7-1907
# 3-1909
# 8-1910
# 5-1911
# 1-1912
# 7-1912
# 12-1913
# 3-1915
# 5-1916
# 1-1917
# 10-1917
# 7-1918
# 12-1919
# 3-1920
# 8-1921
# 5-1922
# 1-1923
# 10-1923
# 12-1924
# 3-1926
# 8-1927
# 10-1928
# 7-1929
# 12-1930
# 8-1932
# 5-1933
# 1-1934
# 10-1934
# 7-1935
# 3-1937
# 8-1938
# 5-1939
# 1-1940
# 7-1940
# 12-1941
# 3-1943
# 5-1944
# 1-1945
# 10-1945
# 7-1946
# 12-1947
# 3-1948
# 8-1949
# 5-1950
# 1-1951
# 10-1951
# 12-1952
# 3-1954
# 8-1955
# 10-1956
# 7-1957
# 12-1958
# 8-1960
# 5-1961
# 1-1962
# 10-1962
# 7-1963
# 3-1965
# 8-1966
# 5-1967
# 1-1968
# 7-1968
# 12-1969
# 3-1971
# 5-1972
# 1-1973
# 10-1973
# 7-1974
# 12-1975
# 3-1976
# 8-1977
# 5-1978
# 1-1979
# 10-1979
# 12-1980
# 3-1982
# 8-1983
# 10-1984
# 7-1985
# 12-1986
# 8-1988
# 5-1989
# 1-1990
# 10-1990
# 7-1991
# 3-1993
# 8-1994
# 5-1995
# 1-1996
# 7-1996
# 12-1997
# 3-1999
# 5-2000
# 1-2001
# 10-2001
# 7-2002
# 12-2003
# 3-2004
# 8-2005
# 5-2006
# 1-2007
# 10-2007
# 12-2008
# 3-2010
# 8-2011
# 10-2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment