欧拉计划(python) problem 19

Counting Sundays

Problem 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)?


Answer:
171
Completed on Thu, 16 Apr 2015, 02:05

Go to the thread for problem 19 in the forum.

python code:

def IsLeapYear(year):
    if year%4==0:
        if year%100==0:
            if year%400==0:
                return 1
            else:
                return 0
        return 1
    else:
        return 0

def MonthNumList(year):
    List=[31,28,31,30,31,30,31,31,30,31,30,31]
    if IsLeapYear(year)==1:
        List[1]=29
    return List

startDay=1
count=0
for year in range(1900,2001):
    monthNum=MonthNumList(year)
    for month in range(0,12):
        startDay=(startDay+monthNum[month])%7
        if year>1900 and startDay==0:
            count=count+1

print(count)
时间: 2024-08-13 09:50:29

欧拉计划(python) problem 19的相关文章

欧拉计划(python) problem 17

Number letter counts Problem 17 If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers from 1 to 1000 (one thousand) inclusive were written out in w

欧拉计划(python) problem 65

Convergents of e Problem 65 The square root of 2 can be written as an infinite continued fraction. √2 = 1 + 1   2 + 1     2 + 1       2 + 1         2 + ... The infinite continued fraction can be written, √2 = [1;(2)], (2) indicates that 2 repeats ad

欧拉计划(python) problem 28

Number spiral diagonals Problem 28 Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: 21 22 23 24 25 20  7  8  9 10 19  6  1  2 11 18  5  4  3 12 17 16 15 14 13 It can be verified that th

欧拉计划(python) problem 18

Maximum path sum I Problem 18 By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. 3 7 4 2 4 6 8 5 9 3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top t

欧拉计划(python) problem 1

problem 1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. python code: k3=0; k5=0; result=0; for i in range(1,10

欧拉计划(python) problem 5

Smallest multiple Problem 5 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? python code : imp

欧拉计划(python) problem 7

10001st prime Problem 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? python code : import math sqrt=math.sqrt def func(x): k=int(sqrt(x))+1 for i in range(2,k)

欧拉计划(python) problem 8

Largest product in a series Problem 8 The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 858

欧拉计划(python) problem 26

Reciprocal cycles Problem 26 A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: 1/2 =  0.5 1/3 =  0.(3) 1/4 =  0.25 1/5 =  0.2 1/6 =  0.1(6) 1/7 =  0.(142857) 1/8 =  0.12