Skip to main content

Euler 0020

The Problem:

HowWhat many Sundays fell onis the firstsum of the monthdigits betweenof Jan100! 1where 1901n! means 1x2x3x4x...xn?

Considerations and Dec 31 2000?

Considerations:

There is for sure a number theory mathematical way of handling this... but...

Approach:

WhatFor ifPython wethis justis importedtrivial to produce 100! and then take the sum of the digits by converting to a python calendar modulestring and counted how many Sundays were between then and now?back.

The Code:

import calendarmath

yearfactorial = 1901100

end_yearnumber = 2000

sunday_first_days = 0sum([int(x) for ix in range(year, end_year + 1):
    this_year = calendar.Calendar(str(math.factorial(factorial)).yeardayscalendar(i,12)
    for year in this_year:
        for month in year:
            for week in month:
                if week[6] == 1:
                    sunday_first_days += 1])

print(sunday_first_days)number)