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

4161
day_1/input.txt Normal file

File diff suppressed because it is too large Load Diff

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()

41
day_1/solution2.py Normal file
View File

@@ -0,0 +1,41 @@
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()

10
day_1/testinput.txt Normal file
View File

@@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82