きったんの頭

#! /usr/bin/env python3
"""
pe18.py
https://mind.kittttttan.info/py/pe18

pe18.txt
https://mind.kittttttan.info/c/pe18.txt
"""

def pe18(fname="pe18.txt"):
    """
    Find the maximum sum travelling from the top of the triangle to the base.
    """
    with open(fname, 'r') as f:
        s = f.read()
    s = s.split('\n')
    size = len(s) - 1
    for i in range(size + 1):
        s[i] = s[i].split(' ')
    for i in range(size):
        si = s[size - i - 1]
        for j in range(len(si)):
            si[j] = int(si[j]) + \
                    max(int(s[size - i][j]), int(s[size - i][j + 1]))
    print(s[0][0])

if __name__ == "__main__":
    pe18()