示例#1
0

def part1(data):
    total = 0
    for y in range(50):
        for x in range(50):
            total += check(data, x, y)
    return total


def part2(data):
    bottom_edge = [9, 5]
    top_edge = [9, 4]
    square_found = False
    while not square_found:
        bottom_edge[0] += 1
        while check(data, bottom_edge[0], bottom_edge[1]) == 1:
            bottom_edge[1] += 1
        bottom_edge[1] -= 1
        top_edge[0] += 1
        while check(data, top_edge[0], top_edge[1]) != 1:
            top_edge[1] += 1
        if bottom_edge[1] - top_edge[1] >= 99:
            if check(data, bottom_edge[0] + 99, bottom_edge[1] - 99) == 1:
                square_found = True
    return bottom_edge[0] * 10000 + bottom_edge[1] - 99


INPUT = get_formatted_input(19)
print(part1(INPUT), part2(INPUT))
示例#2
0
            this_total = 0
            for k in range(signal_length):
                this_total = this_total + BASE_PATTERN[((k + 1) % (4 * (j + 1)) // (j + 1))] * int(sample[k])
            output.append(str(abs(this_total) % 10))
        sample = "".join(output)

    return sample


def part1(data):
    return run_ftt(data, 100)[:8]


def part2(data):
    data = data * 10000
    signal = data[int(data[:7]):]
    print(len(signal))
    phases = 100
    for i in range(phases):
        output = []
        this_total = sum([int(signal[x]) for x in range(len(signal))])
        for k in range(len(signal)):
            output.append(this_total % 10)
            this_total -= int(signal[k])
        signal = "".join(str(x) for x in output)
    return signal[:8]


INPUT = str(get_formatted_input(16))
print(part1(INPUT), part2(INPUT))