Project Euler Problem 13 Statement
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 … {data continues}
Solution
Summing a set of 50–digit numbers uses Python’s intrinsic arbitrary–precision integers and arithmetic.
N is read first and then N lines are read from input as strings and converted to integers. The integers are summed, and the sum converted to a string and the first 10 characters of the sum are printed.
print(str(sum(int(input()) for _ in range(int(input()))))[:10])
HackerRank version
HackerRank Project Euler 13 increases the quantity of 50–digit numbers from 100 to 1,000. No changes are required.
Python Source Code
print(str(sum(int(input()) for _ in range(int(input()))))[:10])
Last Word
I'm fully aware that the intention was to use some Cold War era technology to solve this. I am inherently lazy and this suited me quite well. I'm sure there are other legacy solutions out there that are more clever than this.