valmis
This commit is contained in:
49
8/advent_1.py
Normal file
49
8/advent_1.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env python3.12
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class RL:
|
||||||
|
def __init__(self,L ,R ):
|
||||||
|
self.directions = {}
|
||||||
|
self.directions['R'] = R
|
||||||
|
self.directions['L'] = L
|
||||||
|
|
||||||
|
def get(self, direction):
|
||||||
|
return self.directions[direction]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"L: {self.get('L')} R: {self.get('R')}"
|
||||||
|
|
||||||
|
|
||||||
|
with open("data.txt") as file:
|
||||||
|
lines = [line.rstrip() for line in file]
|
||||||
|
|
||||||
|
|
||||||
|
x = 0
|
||||||
|
maps = {}
|
||||||
|
for line in lines:
|
||||||
|
print(line)
|
||||||
|
if x == 0:
|
||||||
|
instructions = line
|
||||||
|
x += 1
|
||||||
|
continue
|
||||||
|
if line == '':
|
||||||
|
print('Tühi rida')
|
||||||
|
continue
|
||||||
|
temp = re.findall(r'\w+', line)
|
||||||
|
z = list(temp)
|
||||||
|
maps[z[0]] = RL(z[1], z[2])
|
||||||
|
|
||||||
|
for i in maps:
|
||||||
|
print(i)
|
||||||
|
print(maps[i])
|
||||||
|
|
||||||
|
vastus = 'AAA'
|
||||||
|
x = 0
|
||||||
|
while vastus != "ZZZ":
|
||||||
|
print(vastus)
|
||||||
|
vastus = maps[vastus].get(instructions[x % len(instructions)])
|
||||||
|
x += 1
|
||||||
|
|
||||||
|
print(x)
|
||||||
Reference in New Issue
Block a user