0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Project Euler】Problem 19: 日曜日を数える

Posted at
  • 本記事はProjectEulerの「100番以下の問題の説明は記載可能」という規定に基づいて回答のヒントが書かれていますので、自分である程度考えてみてから読まれることをお勧めします。

問題 19. 日曜日を数える

原文 Problem 19: Counting Sundays

問題の要約:20世紀の日曜日の数を数えよ

問題には親切に、2月は普通28日、うるう年は29日、ただし100年に一度は違うけど400年に一度はうるう年、等の説明があるので自力で書けと言うことだと思いますが、、ここはpythonのdatetimeを使って簡単に、、、weekday()メソッドの出力は6が日曜日のようです。

import datetime
print([datetime.date(year,month,1).weekday() 
        for month in range(1,12+1) 
        for year in range(1901,2000+1)].count(6))

(開発環境:Google Colab)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?