통계, IT, AI

19. Counting Sundays, 20. Factorial digit sum 본문

IT/PROJECT_EULER

19. Counting Sundays, 20. Factorial digit sum

Harold_Finch 2017. 1. 18. 00:32

1. 개요

풀이가 워낙 간단하여 19, 20번 두 문제를 푼다. 각각의 문제는 이곳이곳에서 확인할 수 있다. 19번 문제의 목표는 1901년 1월 1일부터 2000년 12월 31일에서 각 월의 1일이 일요일인 날의 수를  세는 것이다. 20번 문제는 \(100!\)의 각 자리의 수를 더하는 것이다. 

2. Ver 1.0

# -*- coding: utf-8 -*-
import datetime, math

# 19. Counting Sundays
print(sum(1 for y in range(1901, 2001)
          for m in range(1, 13)
          if datetime.date(y, m, 1).weekday() == 6 ))

# 20. Factorial digit sum
print(sum(int(i) for i in str(math.factorial(100))))

답은 각각 171, 648이다.


'IT > PROJECT_EULER' 카테고리의 다른 글

23. Non-abundant sums  (0) 2017.01.27
21. Amicable numbers  (0) 2017.01.23
18. Maximum path sum I  (0) 2017.01.15
17. Number letter counts  (0) 2017.01.12
15. Lattice paths, 16. Power digit sum  (0) 2017.01.12
Comments