mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement 2019 day 16 part 2
This commit is contained in:
@@ -27,7 +27,31 @@ def simulate(numbers: List[int]) -> str:
|
||||
return ''.join(str(s) for s in numbers[:8])
|
||||
|
||||
|
||||
def simulate2(numbers: List[int]) -> str:
|
||||
numbers = numpy.tile(numpy.array(numbers, dtype=numpy.int), 10000)
|
||||
starting_index = 0
|
||||
|
||||
for n in numbers[:7]:
|
||||
starting_index *= 10
|
||||
starting_index += n
|
||||
|
||||
assert starting_index > len(numbers) / 2
|
||||
|
||||
numbers = numbers[starting_index:]
|
||||
|
||||
for _ in range(100):
|
||||
numbers = numpy.abs(numpy.flip(numpy.cumsum(numpy.flip(numbers)))) % 10
|
||||
|
||||
return ''.join(str(s) for s in numbers[:8])
|
||||
|
||||
|
||||
def part1(data: TextIO) -> str:
|
||||
numbers = read_input(data)
|
||||
|
||||
return simulate(numbers)
|
||||
|
||||
|
||||
def part2(data: TextIO) -> str:
|
||||
numbers = read_input(data)
|
||||
|
||||
return simulate2(numbers)
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from aoc2019.day16 import simulate
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data,correct', [
|
||||
('80871224585914546619083218645595', '24176176'),
|
||||
('19617804207202209144916044189917', '73745418'),
|
||||
('69317163492948606335995924319873', '52432133'),
|
||||
])
|
||||
def test_sample_part1(data: str, correct: str):
|
||||
numbers = [int(c) for c in data]
|
||||
|
||||
assert simulate(numbers) == correct
|
||||
pass
|
||||
25
2019/tests/test_day16.py
Normal file
25
2019/tests/test_day16.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
from aoc2019.day16 import simulate, simulate2
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data,correct', [
|
||||
('80871224585914546619083218645595', '24176176'),
|
||||
('19617804207202209144916044189917', '73745418'),
|
||||
('69317163492948606335995924319873', '52432133'),
|
||||
])
|
||||
def test_sample_part1(data: str, correct: str):
|
||||
numbers = [int(c) for c in data]
|
||||
|
||||
assert simulate(numbers) == correct
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data,correct', [
|
||||
('03036732577212944063491565474664', '84462026'),
|
||||
('02935109699940807407585447034323', '78725270'),
|
||||
('03081770884921959731165446850517', '53553731'),
|
||||
])
|
||||
def test_sample_part2(data: str, correct: str):
|
||||
numbers = [int(c) for c in data]
|
||||
|
||||
assert simulate2(numbers) == correct
|
||||
Reference in New Issue
Block a user