Skip to content

Commit

Permalink
AoC 2023 Day 9 Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pareronia committed Dec 9, 2023
1 parent ad2db4e commit a0f2d45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- @BEGIN:ImplementationsTable:2023@ -->
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| ---| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| python3 | [](src/main/python/AoC2023_01.py) | [](src/main/python/AoC2023_02.py) | [](src/main/python/AoC2023_03.py) | [](src/main/python/AoC2023_04.py) | [](src/main/python/AoC2023_05.py) | [](src/main/python/AoC2023_06.py) | [](src/main/python/AoC2023_07.py) | [](src/main/python/AoC2023_08.py) | | | | | | | | | | | | | | | | | |
| python3 | [](src/main/python/AoC2023_01.py) | [](src/main/python/AoC2023_02.py) | [](src/main/python/AoC2023_03.py) | [](src/main/python/AoC2023_04.py) | [](src/main/python/AoC2023_05.py) | [](src/main/python/AoC2023_06.py) | [](src/main/python/AoC2023_07.py) | [](src/main/python/AoC2023_08.py) | [](src/main/python/AoC2023_09.py) | | | | | | | | | | | | | | | | |
| java | [](src/main/java/AoC2023_01.java) | [](src/main/java/AoC2023_02.java) | [](src/main/java/AoC2023_03.java) | [](src/main/java/AoC2023_04.java) | | [](src/main/java/AoC2023_06.java) | | [](src/main/java/AoC2023_08.java) | | | | | | | | | | | | | | | | | |
| bash | | | | | | | | | | | | | | | | | | | | | | | | | |
| c++ | | | | | | | | | | | | | | | | | | | | | | | | | |
Expand Down
20 changes: 13 additions & 7 deletions src/main/python/AoC2023_09.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from aoc.common import InputData
from aoc.common import SolutionBase
from aoc.common import aoc_samples
from aoc.common import log

Input = list[list[int]]
Output1 = int
Expand All @@ -30,28 +29,35 @@ def parse_input(self, input_data: InputData) -> Input:
def part_1(self, input: Input) -> Output1:
ans = 0
for line in input:
log(line)
lasts = deque[int]()
lasts.append(line[-1])
while not all(_ == lasts[-1] for _ in line):
line = [line[i] - line[i - 1] for i in range(1, len(line), 1)]
lasts.append(line[-1])
log(line)
log(lasts)
tmp = lasts.pop()
while len(lasts) > 0:
tmp += lasts.pop()
log(tmp)
ans += tmp
return ans

def part_2(self, input: Input) -> Output2:
return 0
ans = 0
for line in input:
firsts = deque[int]()
firsts.append(line[0])
while not all(_ == firsts[-1] for _ in line):
line = [line[i] - line[i - 1] for i in range(1, len(line), 1)]
firsts.append(line[0])
tmp = firsts.pop()
while len(firsts) > 0:
tmp = firsts.pop() - tmp
ans += tmp
return ans

@aoc_samples(
(
("part_1", TEST, 114),
# ("part_2", TEST, "TODO"),
("part_2", TEST, 2),
)
)
def samples(self) -> None:
Expand Down

0 comments on commit a0f2d45

Please sign in to comment.