48 lines
1.0 KiB
Python
48 lines
1.0 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
# # Puzzle 1 of AoC 2025
|
|
# Author: Victoria Ramírez López
|
|
#
|
|
# Date: December 1, 2025
|
|
|
|
|
|
# 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
|
|
|
|
|
|
# In[97]:
|
|
|
|
# Import instruction file
|
|
instructions = open('vicky_py/input01.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)
|