day15
This commit is contained in:
parent
75d0aa0fc4
commit
10928fd157
55
day15.py
Normal file
55
day15.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(588, "input15_test"),
|
||||||
|
(567, "input15")
|
||||||
|
],
|
||||||
|
[
|
||||||
|
(309, "input15_test"),
|
||||||
|
(323, "input15")
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
factor_a = 16807
|
||||||
|
factor_b = 48271
|
||||||
|
|
||||||
|
def get_generator_start_values(self) -> (int, int):
|
||||||
|
return map(int, map(lambda x: x.split(" ")[-1], self.getInput()))
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
a, b = self.get_generator_start_values()
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for _ in range(40_000_000):
|
||||||
|
a, b = a * self.factor_a % 2147483647, b * self.factor_b % 2147483647
|
||||||
|
if a & 0x0000FFFF == b & 0x0000FFFF:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
a, b = self.get_generator_start_values()
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for _ in range(5_000_000):
|
||||||
|
a = a * self.factor_a % 2147483647
|
||||||
|
while a % 4 != 0:
|
||||||
|
a = a * self.factor_a % 2147483647
|
||||||
|
|
||||||
|
b = b * self.factor_b % 2147483647
|
||||||
|
while b % 8 != 0:
|
||||||
|
b = b * self.factor_b % 2147483647
|
||||||
|
|
||||||
|
if a & 0x0000FFFF == b & 0x0000FFFF:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
day = Day(2017, 15)
|
||||||
|
day.run(verbose=True)
|
||||||
2
inputs/input15
Normal file
2
inputs/input15
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Generator A starts with 512
|
||||||
|
Generator B starts with 191
|
||||||
2
inputs/input15_test
Normal file
2
inputs/input15_test
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Generator A starts with 65
|
||||||
|
Generator B starts with 8921
|
||||||
Loading…
Reference in New Issue
Block a user