aoc2016/day19.py

44 lines
1.1 KiB
Python

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)