Project Euler 19: (Iron)Python

Posted by Ben Griswold on Johnny Coder See other posts from Johnny Coder or by Ben Griswold
Published on Wed, 22 Sep 2010 20:26:52 +0000 Indexed on 2010/12/06 16:59 UTC
Read the original article Hit count: 354

In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 19

As always, any feedback is welcome.

# Euler 19
# http://projecteuler.net/index.php?section=problems&id=19
# You are given the following information, but you may
# prefer to do some research for yourself.
#
# - 1 Jan 1900 was a Monday.
# - Thirty days has September,
#   April, June and November.
#   All the rest have thirty-one,
#   Saving February alone,
#   Which has twenty-eight, rain or shine.
#   And on leap years, twenty-nine.
# - A leap year occurs on any year evenly divisible by 4,
#   but not on a century unless it is divisible by 400.
#
# How many Sundays fell on the first of the month during
# the twentieth century (1 Jan 1901 to 31 Dec 2000)?
import time
start = time.time()

import datetime
sundays = 0

for y in range(1901,2001):
    for m in range(1,13):
        # monday == 0, sunday == 6
        if datetime.datetime(y,m,1).weekday() == 6:
            sundays += 1
print sundays

print "Elapsed Time:", (time.time() - start) * 1000, "millisecs"
a=raw_input('Press return to continue')

© Johnny Coder or respective owner

Related posts about ironpython

Related posts about languages