day19 - pypy takes an hour :)
This commit is contained in:
parent
9f4981fced
commit
1515086794
43
day19.py
Normal file
43
day19.py
Normal file
@ -0,0 +1,43 @@
|
||||
from tools.aoc import AOCDay
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
(3, "input19_test"),
|
||||
(1815603, "input19"),
|
||||
],
|
||||
[
|
||||
(2, "input19_test"),
|
||||
(1410630, "input19"),
|
||||
],
|
||||
]
|
||||
|
||||
def get_elf_list(self) -> list[int]:
|
||||
return list(range(1, int(self.getInput()) + 1))
|
||||
|
||||
def part1(self) -> Any:
|
||||
elf_list = self.get_elf_list()
|
||||
while len(elf_list) > 1:
|
||||
is_odd = len(elf_list) % 2 == 1
|
||||
elf_list = [x for i, x in enumerate(elf_list) if i % 2 == 0]
|
||||
if is_odd:
|
||||
elf_list = [elf_list[-1]] + elf_list[:-1]
|
||||
|
||||
return elf_list[0]
|
||||
|
||||
def part2(self) -> Any:
|
||||
elf_list = self.get_elf_list()
|
||||
max = len(elf_list)
|
||||
while len(elf_list) > 1:
|
||||
elf_list.pop(len(elf_list) // 2)
|
||||
first_elf = elf_list.pop(0)
|
||||
elf_list.append(first_elf)
|
||||
self.progress(max)
|
||||
return elf_list[0]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
day = Day(2016, 19)
|
||||
day.run(verbose=True)
|
||||
1
inputs/input19
Normal file
1
inputs/input19
Normal file
@ -0,0 +1 @@
|
||||
3004953
|
||||
1
inputs/input19_test
Normal file
1
inputs/input19_test
Normal file
@ -0,0 +1 @@
|
||||
5
|
||||
Loading…
Reference in New Issue
Block a user