Example #1
0
def ans():
    # all hexagon numbers are also triangle numbers
    i: int = 144  # we should find the next after 143
    while True:
        if is_int(hex_and_pent_number(i)):
            return polygonal_number(i, 6)
        i += 1
Example #2
0
def apply_step_backwards(number: int, step: str) -> Optional[int]:
    """
    :param number: a result number
    :param step: the step that was taken
    :return: the origin number
    """
    if step == "D":
        return 3 * number
    if step == "U":
        res = (3 * number - 2) / 4
        if is_int(res) and int(res) % 3 == 1:
            return int(res)
    if step == "d":
        res = (3 * number + 1) / 2
        if is_int(res) and int(res) % 3 == 2:
            return int(res)
    return None
Example #3
0
def ans():
    count_list: Dict[int, int] = defaultdict(int)
    # go over all possible lengths
    for a in range(1, 500):
        ap2 = a ** 2
        for b in range(1, a):
            c = sqrt(ap2 + b ** 2)
            if is_int(c):
                # we found a triple
                c = int(c)
                p = a + b + c
                if p <= 1000:
                    count_list[p] += 1
    return max(count_list, key=lambda k: count_list[k])
Example #4
0
def is_polygonal_number(num: int, shape: int) -> bool:
    # n=(sqrt(8x(s-2)+(s-4)^2)+s-4)/2
    n = (math.sqrt(8 * num * (shape - 2) +
                   (shape - 4)**2) + shape - 4) / (2 * (shape - 2))
    return is_int(n)
Example #5
0
def ans():
    for i in range(1, 100000):
        for j in range(1, i):
            if is_int(pent_difference(i, j)) and is_int(pent_sum(i, j)):
                return polygonal_number(int(pent_difference(i, j)), 5)