1
0

solved part 1 day 1.. working on part 2

This commit is contained in:
2025-12-07 03:00:13 +01:00
commit e776ba5d17
4 changed files with 4251 additions and 0 deletions

39
day_1/solution1.py Normal file
View File

@@ -0,0 +1,39 @@
class Dial:
value = 50
reached_zero = 0
def CrankLeft(self, clicks):
self.value -= clicks
if self.value < 0:
self.value = abs(self.value % int(100))
if self.value == 0:
self.reached_zero += 1
def CrankRight(self, clicks):
self.value += clicks
if self.value > 99:
self.value = abs(self.value % int(100))
if self.value == 0:
self.reached_zero += 1
def PrintValue(self):
print(self.value)
def printSolution(self):
print( f'The dial reached zero {self.reached_zero} times')
MyDial = Dial()
file = input("enter input file:")
with open(file) as f:
for line in f:
ticks = int(line[1:-1])
if line[0] == 'L':
print("Crank Left")
MyDial.CrankLeft(ticks)
elif line[0] == 'R':
print("Crank Right")
MyDial.CrankRight(ticks)
MyDial.PrintValue()
MyDial.printSolution()