I am working on Project Euler Problem 8 so please avoid going too far in your answer.
Where is the problem in the code such that when I add the int conversion, the output changes and some groups are no longer 13 digits. This happens multiple times throughout but an easy one to spot is 5th in from the last.
def large_product(n):
string_n = str(n)
n = [int(str_n[i:i+13]) for i in range(0, len(str_n), 13)]
print(n)
What is happening when I add the int conversion that causes the output to change and some groups are no longer 13 digits? This happens multiple times throughout but an easy one to spot is the first below:
5593572972, 5716362695618, 8267042825248, 3600823257530, 420752963450
If I remove the int and get back a list of strings, they are all the correct 13 digits in length but then I cannot convert back to int and will constantly get hit with an "invalid literal for int() with base 10" message.
n = [(str_n[i:i+13]) for i in range(0, len(str_n), 13)]
str_n = str(n)
int_n = int(str_n)
print(int_n)
Returns:
ValueError: invalid literal for int() with base 10: "['7316717653133', '0624919225119', '6744265747423', '5534919493496', '9835203127745', '0632623957831', '8016984801869', '4788518438586', '1560789112949', '4954595017379', '5833195285320', '8805511125
How do you get these groups of numbers in a position to be multiplied together and then compared? Thanks in advance.