Add executable file.
parent
0f45ec9393
commit
b42c2a8852
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
# # Puzzle 1 of AoC 2025
|
||||
# Author: Victoria Ramírez López
|
||||
#
|
||||
# Date: December 1, 2025
|
||||
|
||||
# In[97]:
|
||||
|
||||
|
||||
# Import instruction file
|
||||
instructions = open('dummy_input.txt','r')
|
||||
|
||||
|
||||
# In[98]:
|
||||
|
||||
|
||||
# Calculate passcode
|
||||
dial_position = 50
|
||||
passcode = 0
|
||||
|
||||
for instruction in instructions:
|
||||
dial_position = rotate_dial(instruction, dial_position)
|
||||
if dial_position == 0:
|
||||
passcode = passcode + 1
|
||||
|
||||
print(passcode)
|
||||
|
||||
|
||||
# In[89]:
|
||||
|
||||
|
||||
def rotate_dial(instruction = '', dial_position=50):
|
||||
# This function rotates the dial based on the input from the set of instructions
|
||||
# input: instruction = String
|
||||
# output: dial_position
|
||||
|
||||
# Split the instruction into "direction" and "distance"
|
||||
direction = instruction[0]
|
||||
distance = int(instruction[1:])
|
||||
|
||||
# Calculate final position of the dial
|
||||
if direction == 'R':
|
||||
dial_position = (dial_position + distance) % 100
|
||||
elif direction == 'L':
|
||||
dial_position = (dial_position - distance) % 100
|
||||
|
||||
return dial_position
|
||||
|
||||
Loading…
Reference in New Issue