diff --git a/day19.py b/day19.py new file mode 100644 index 0000000..a9a1ac7 --- /dev/null +++ b/day19.py @@ -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) diff --git a/inputs/input19 b/inputs/input19 new file mode 100644 index 0000000..f652d11 --- /dev/null +++ b/inputs/input19 @@ -0,0 +1 @@ +3004953 diff --git a/inputs/input19_test b/inputs/input19_test new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/inputs/input19_test @@ -0,0 +1 @@ +5 \ No newline at end of file