day06
This commit is contained in:
parent
c98135a75a
commit
8e397e4442
40
day06.py
Normal file
40
day06.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
from aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
test_solutions_p1 = [42]
|
||||||
|
test_solutions_p2 = [4]
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
tree = {}
|
||||||
|
for l in self.getInputAsArraySplit(')'):
|
||||||
|
tree[l[1]] = l[0]
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for child, parent in tree.items():
|
||||||
|
count += 1
|
||||||
|
while parent != "COM":
|
||||||
|
parent = tree[parent]
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
tree = {}
|
||||||
|
for l in self.getInputAsArraySplit(')'):
|
||||||
|
tree[l[1]] = l[0]
|
||||||
|
|
||||||
|
source = tree["YOU"]
|
||||||
|
target = tree["SAN"]
|
||||||
|
path = []
|
||||||
|
while source != "COM":
|
||||||
|
path.append(source)
|
||||||
|
source = tree[source]
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
while target not in path:
|
||||||
|
count += 1
|
||||||
|
target = tree[target]
|
||||||
|
|
||||||
|
return count + path.index(target)
|
||||||
1651
inputs/input06
Normal file
1651
inputs/input06
Normal file
File diff suppressed because it is too large
Load Diff
11
inputs/test_input06_1_0
Normal file
11
inputs/test_input06_1_0
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
COM)B
|
||||||
|
B)C
|
||||||
|
C)D
|
||||||
|
D)E
|
||||||
|
E)F
|
||||||
|
B)G
|
||||||
|
G)H
|
||||||
|
D)I
|
||||||
|
E)J
|
||||||
|
J)K
|
||||||
|
K)L
|
||||||
13
inputs/test_input06_2_0
Normal file
13
inputs/test_input06_2_0
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
COM)B
|
||||||
|
B)C
|
||||||
|
C)D
|
||||||
|
D)E
|
||||||
|
E)F
|
||||||
|
B)G
|
||||||
|
G)H
|
||||||
|
D)I
|
||||||
|
E)J
|
||||||
|
J)K
|
||||||
|
K)L
|
||||||
|
K)YOU
|
||||||
|
I)SAN
|
||||||
Loading…
Reference in New Issue
Block a user