This commit is contained in:
Stefan Harmuth 2022-11-20 07:30:58 +01:00
parent 64c888dc50
commit 0ea4056bb2
4 changed files with 50 additions and 0 deletions

47
day06.py Normal file
View File

@ -0,0 +1,47 @@
from tools.aoc import AOCDay
from typing import Any
class Day(AOCDay):
inputs = [
[
(5, "input6_test"),
(12841, "input6")
],
[
(4, "input6_test"),
(8038, "input6")
]
]
def distribute(self, p2: bool = False) -> int:
bank = self.getInputAsArraySplit("\t", int)
count = 0
seen = [",".join(map(str, bank))]
while True:
count += 1
i, c = bank.index(max(bank)), max(bank)
bank[i] = 0
while c > 0:
i += 1
bank[i%len(bank)] += 1
c -= 1
seq = ",".join(map(str, bank))
if seq in seen:
if p2:
return count - seen.index(seq)
else:
return count
else:
seen.append(seq)
def part1(self) -> Any:
return self.distribute()
def part2(self) -> Any:
return self.distribute(True)
if __name__ == '__main__':
day = Day(2017, 6)
day.run(verbose=True)

1
inputs/input5_test Normal file
View File

@ -0,0 +1 @@
0 2 7 0

1
inputs/input6 Normal file
View File

@ -0,0 +1 @@
4 10 4 1 8 4 9 14 5 1 14 15 0 15 3 5

1
inputs/input6_test Normal file
View File

@ -0,0 +1 @@
0 2 7 0