mirror of
https://github.com/Noettore/AdventOfCode.git
synced 2025-10-14 19:26:39 +02:00
AoC 2020: day25
Signed-off-by: Ettore Dreucci <ettore.dreucci@gmail.com>
This commit is contained in:
2
2020-python/inputs/day_25
Normal file
2
2020-python/inputs/day_25
Normal file
@@ -0,0 +1,2 @@
|
||||
1614360
|
||||
7734663
|
52
2020-python/solutions/day_25.py
Normal file
52
2020-python/solutions/day_25.py
Normal file
@@ -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()
|
@@ -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) |
|
||||
|
Reference in New Issue
Block a user