diff --git a/2020-python/inputs/day_25 b/2020-python/inputs/day_25 new file mode 100644 index 0000000..fe7ecff --- /dev/null +++ b/2020-python/inputs/day_25 @@ -0,0 +1,2 @@ +1614360 +7734663 diff --git a/2020-python/solutions/day_25.py b/2020-python/solutions/day_25.py new file mode 100644 index 0000000..26c9bd3 --- /dev/null +++ b/2020-python/solutions/day_25.py @@ -0,0 +1,52 @@ +"""AOC 2020 Day 25""" + +import pathlib +import time + +TEST_INPUT = """5764801 +17807724""" + +def read_input(input_path: str) -> str: + """take input file path and return a str with the file's content""" + with open(input_path, 'r') as input_file: + input_data = input_file.read().strip() + return input_data + +def extract(input_data: str) -> tuple: + """take input data and return the appropriate data structure""" + return tuple(map(int, input_data.splitlines())) + +def part1(entries: tuple) -> int: + """part1 solver""" + card_key, door_key = entries + loop_size = 0 + key = 1 + while key not in (card_key, door_key): + loop_size += 1 + key = (key * 7) % 20201227 + + if key == card_key: + return pow(door_key, loop_size, 20201227) + return pow(card_key, loop_size, 20201227) + +def test_input_day_25(): + """pytest testing function""" + entries = extract(TEST_INPUT) + assert part1(entries) == 14897079 + +def test_bench_day_25(benchmark): + """pytest-benchmark function""" + benchmark(main) + +def main(): + """main function""" + input_path = str(pathlib.Path(__file__).resolve().parent.parent) + "/inputs/" + str(pathlib.Path(__file__).stem) + start_time = time.time() + input_data = read_input(input_path) + entries = extract(input_data) + print("Part 1: %s" % part1(entries)) + end_time = time.time() + print("Execution time: %f" % (end_time-start_time)) + +if __name__ == "__main__": + main() diff --git a/README.md b/README.md index 7a5bdf4..9a849dc 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,4 @@ | [Day 22](https://adventofcode.com/2020/day/22) | [1.516s](./2020-python/solutions/day_22.py) | [1.353s](./2020-python/solutions/day_22.py) | | [Day 23](https://adventofcode.com/2020/day/23) | [14.754s](./2020-python/solutions/day_23.py) | [3.572s](./2020-python/solutions/day_23.py) | | [Day 24](https://adventofcode.com/2020/day/24) | [753.985ms](./2020-python/solutions/day_24.py) | [357.455ms](./2020-python/solutions/day_24.py) | +| [Day 25](https://adventofcode.com/2020/day/25) | [144.685ms](./2020-python/solutions/day_25.py) | [4.184ms](./2020-python/solutions/day_25.py) |