예제 #1
0
def problem_45():
    tris = utils.triangulars()
    desired_index = 2
    current_index = 0
    for num in tris:
        if utils.is_hexagonal(num) and utils.is_pentagonal(num):
            if current_index == desired_index:
                return num
            current_index += 1
예제 #2
0
def problem_45():
    tris = utils.triangulars()
    desired_index = 2
    current_index = 0
    for num in tris:
        if utils.is_hexagonal(num) and utils.is_pentagonal(num):
            if current_index == desired_index:
                return num
            current_index += 1
예제 #3
0
def problem_44(): #TOO slow

    starting_size = 10000
    pentags = utils.pentagonals()
    p = [pentags.next() for i in xrange(starting_size)]
    p_set = set(p)
    combs = itertools.combinations(p, 2)

    diffs = []
    for c in combs:
        if c[0] + c[1] > p[-1]:
            if utils.is_pentagonal(c[0] + c[1]) and utils.is_pentagonal(abs(c[1] - c[0])):
                diffs.append(abs(c[0]-c[1]))
        else:
            if (c[0] + c[1]) in p_set and abs(c[1] - c[0]) in p_set:
                diffs.append(abs(c[0] - c[1]))

    return diffs
예제 #4
0
def problem_44():  #TOO slow

    starting_size = 10000
    pentags = utils.pentagonals()
    p = [pentags.next() for i in xrange(starting_size)]
    p_set = set(p)
    combs = itertools.combinations(p, 2)

    diffs = []
    for c in combs:
        if c[0] + c[1] > p[-1]:
            if utils.is_pentagonal(c[0] + c[1]) and utils.is_pentagonal(
                    abs(c[1] - c[0])):
                diffs.append(abs(c[0] - c[1]))
        else:
            if (c[0] + c[1]) in p_set and abs(c[1] - c[0]) in p_set:
                diffs.append(abs(c[0] - c[1]))

    return diffs