21 lines
648 B
Python
Executable File
21 lines
648 B
Python
Executable File
#!/usr/bin/env python3.11
|
|
from typing import List
|
|
|
|
from data import Node, parse
|
|
|
|
|
|
def count_steps_AAA_ZZZ(directions:str , node_list: List[Node]) -> int:
|
|
count = 0
|
|
current_node = list(filter(lambda n:n.value == 'AAA', node_list))[0]
|
|
while current_node.value != 'ZZZ':
|
|
current_node = current_node.move_left(node_list) if directions[count % len(directions)] == 'L' else current_node.move_right(node_list)
|
|
count += 1
|
|
return count
|
|
|
|
if __name__ == '__main__':
|
|
directions, node_list = parse('input.txt')
|
|
count = count_steps_AAA_ZZZ(directions, node_list)
|
|
print(count)
|
|
|
|
|
|
|