Skip to main content

Euler 0016

The Problem:

HowWhat manyis pathsthe can you take if you just walk through a grid by only moving down and right?
We are looking for 20x20. 2x2 has a given valuesum of 6.the digits of 2^1000?

Considerations:

AsWith python we can trivially calculate 2^1000 and then we can convert it turnsto out,a thisstring isand justsum theits max value of all the odd layers of pascal's triangle.  digits.
1  
1 1  
1 2 1  
1 3 3 1  
1 4 6 4 1  

The Approach:

SoWe ifcalculate we2^1000 generate 41 rows of pascaland then we can takeconvert theit maxto valuea string and thatsum isits the answer.digits.


The Code:

pascal_rowspower = 411000
def generate_pascals_last_row(rows):
    last_rownumber = [1]2**power

#wetotal_sum have= already generated row 10
for idigit in range(rows-1)str(number):
    #take the first number (hint, it's 1)
        current_row = [1]

        #add up all the numbers and put them in between
        for j in range(0, len(last_row) - 1):
            current_rowtotal_sum += [last_row[j] + last_row[j+1]]

        #take the last number (hint, it's 1)
        current_row += [1]
        last_row = current_row 
    
    return last_rowint(digit)

print(max(generate_pascals_last_row(pascal_rows)))
total_sum)