Beispiel #1
0
def pe22(fname="../../res/pe22.txt"):
    """
    >>> pe22()
    871198282
    """
    with open(fname, 'r') as f:
        names_string = f.read()
    names = names_string.replace('"', '').split(',')
    names.sort()
    return sum(word_worth(names[i]) * (i + 1) for i in range(len(names)))
Beispiel #2
0
def pe22(fname="../../res/pe22.txt"):
    """
    >>> pe22()
    871198282
    """
    with open(fname, 'r') as f:
        names_string = f.read()
    names = names_string.replace('"', '').split(',')
    names.sort()
    return sum(word_worth(names[i]) * (i + 1) for i in range(len(names)))
Beispiel #3
0
def pe42(fname="../../res/pe42.txt"):
    """
    >>> pe42()
    162
    """
    with open(fname, 'r') as f:
        words = f.read()
    words = words.replace('"', '').split(',')
    triangles = set(i * (i + 1) >> 1 for i in range(1, 100))
    # print([w for w in words if worth(w) in triangles])
    return sum([1 for w in words if word_worth(w) in triangles])
Beispiel #4
0
def pe42(fname="../../res/pe42.txt"):
    """
    >>> pe42()
    162
    """
    with open(fname, "r") as f:
        words = f.read()
    words = words.replace('"', "").split(",")
    triangles = set(i * (i + 1) >> 1 for i in range(1, 100))
    # print([w for w in words if worth(w) in triangles])
    return sum([1 for w in words if word_worth(w) in triangles])