42 lines
930 B
Python
42 lines
930 B
Python
import math
|
|
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(f'Dial at {self.value}')
|
|
|
|
def printSolution(self):
|
|
print( f'The dial reached zero {self.reached_zero} times')
|
|
|
|
|
|
MyDial = Dial()
|
|
file = input("enter input file:")
|
|
MyDial.PrintValue()
|
|
with open(file) as f:
|
|
for line in f:
|
|
ticks = int(line[1:-1])
|
|
if line[0] == 'L':
|
|
print(f'Crank Left {ticks}')
|
|
MyDial.CrankLeft(ticks)
|
|
elif line[0] == 'R':
|
|
print(f'Crank Right {ticks}')
|
|
MyDial.CrankRight(ticks)
|
|
MyDial.PrintValue()
|
|
MyDial.printSolution()
|
|
|