Exemple #1
0
from aoc2020.dayCHANGEME import solution
from aoc2020.util import get_input_as_int


input_data = get_input_as_int("tests/testinput.dayCHANGEME")


def test_solve_part1():
    expected = None
    actual = solution.solve_part1(input_data)
    assert expected == actual


def test_solve_part2():
    expected = None
    actual = solution.solve_part2(input_data)
    assert expected == actual
Exemple #2
0
from aoc2020.day09 import solution
from aoc2020.util import get_input_as_int

input_data = get_input_as_int("tests/testinput.day09")


def test_solve_part1():
    expected = 127
    preamble_length = 5
    actual = solution.solve_part1(input_data, preamble_length)
    assert expected == actual


def test_solve_part2():
    expected = 62
    actual = solution.solve_part2(input_data, 127)
    assert expected == actual
Exemple #3
0
from aoc2020.day10 import solution
from aoc2020.util import get_input_as_int

input_data = get_input_as_int("tests/testinput.day10")
input_data2 = get_input_as_int("tests/testinput.day10.2")


def test_get_device_rating():
    expected = 22
    actual = solution.get_device_rating(input_data)
    assert expected == actual


def test_solve_part1():
    expected = 35
    actual = solution.solve_part1(input_data)
    assert expected == actual


def test_solve_part1_2():
    expected = 220
    actual = solution.solve_part1(input_data2)
    assert expected == actual


def test_solve_part2():
    expected = 8
    actual = solution.solve_part2(input_data)
    assert expected == actual

Exemple #4
0
            for comb in combinations(numbers[i - preamble_length:i], 2)
        ])
        if to_check not in sums:
            return to_check
        i += 1
    return


def solve_part1(entries, preamble_length):
    result = find_first_invalid_number(entries, preamble_length)
    return result


def solve_part2(entries, invalid_number):
    start = 0
    while start < len(entries):
        end = 0
        while end < len(entries):
            to_check = entries[start:end]
            if invalid_number == sum(to_check):
                return min(to_check) + max(to_check)
            end += 1
        start += 1


if __name__ == "__main__":  # pragma: no cover
    entries = get_input_as_int("aoc2020/day09/input")
    invalid_number = solve_part1(entries, preamble_length=25)
    print(invalid_number)
    print(solve_part2(entries, invalid_number))
Exemple #5
0
def test_get_input_as_int():
    expected = [1, 2, 3, 4]
    actual = util.get_input_as_int(input_file)
    assert actual == expected