2019-07-16 23:09:53 +00:00
|
|
|
"""
|
2020-10-10 15:53:17 +00:00
|
|
|
Problem 13: https://projecteuler.net/problem=13
|
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
Problem Statement:
|
2019-07-16 23:09:53 +00:00
|
|
|
Work out the first ten digits of the sum of the following one-hundred 50-digit
|
|
|
|
numbers.
|
|
|
|
"""
|
2024-03-13 06:52:41 +00:00
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
import os
|
2018-10-19 12:48:28 +00:00
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
def solution():
|
|
|
|
"""
|
|
|
|
Returns the first ten digits of the sum of the array elements
|
|
|
|
from the file num.txt
|
2019-07-25 07:49:00 +00:00
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
>>> solution()
|
2019-07-16 23:09:53 +00:00
|
|
|
'5537376230'
|
|
|
|
"""
|
2020-10-10 15:53:17 +00:00
|
|
|
file_path = os.path.join(os.path.dirname(__file__), "num.txt")
|
2020-10-21 10:46:14 +00:00
|
|
|
with open(file_path) as file_hand:
|
2021-09-07 11:37:03 +00:00
|
|
|
return str(sum(int(line) for line in file_hand))[:10]
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2019-07-16 23:09:53 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-10-10 15:53:17 +00:00
|
|
|
print(solution())
|