Exemple #1
0
def problem22(file_path):
    f = codecs.open(file_path, 'rU')
    names = f.read()
    names = re.sub('",', '\n', names)
    names = re.sub('"', '', names)
    names = names.split()
    names.sort()
    total = 0
    for pos in range(len(names)):
        name = names[pos]
        value = 0
        for i in range(len(name)):
            value += helper.letter_position(name[i])
        total += (value * (pos + 1))
    return total
Exemple #2
0
def problem41(file_path):
    f = codecs.open(file_path, 'rU')
    words = f.read()
    words = re.sub('",', '\n', words)
    words = re.sub('"', '', words)
    words = words.split()
    words.sort()
    total = 0
    for word in words:
        value = 0
        for character in word:
            value += helper.letter_position(character)
        term = helper.triangle_pos(value)
        if int(term) == term:
            total += 1
    return total