100 lines
2.3 KiB
Plaintext
100 lines
2.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "40aac862-406a-498f-8138-a93a3eca5aa8",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Puzzle 1 of AoC 2025\n",
|
|
"Author: Victoria Ramírez López \n",
|
|
"\n",
|
|
"Date: December 1, 2025"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 97,
|
|
"id": "7545bee7-c72d-4755-a191-b0803ca31c11",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Import instruction file\n",
|
|
"instructions = open('dummy_input.txt','r')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 98,
|
|
"id": "87fab12e-84fd-4949-a914-ed722bd28737",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"3\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Calculate passcode\n",
|
|
"dial_position = 50\n",
|
|
"passcode = 0\n",
|
|
"\n",
|
|
"for instruction in instructions:\n",
|
|
" dial_position = rotate_dial(instruction, dial_position)\n",
|
|
" if dial_position == 0:\n",
|
|
" passcode = passcode + 1\n",
|
|
"\n",
|
|
"print(passcode)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 89,
|
|
"id": "7689f8ae-6d8a-4116-8188-7678bfac793d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def rotate_dial(instruction = '', dial_position=50):\n",
|
|
" # This function rotates the dial based on the input from the set of instructions\n",
|
|
" # input: instruction = String\n",
|
|
" # output: dial_position\n",
|
|
"\n",
|
|
" # Split the instruction into \"direction\" and \"distance\"\n",
|
|
" direction = instruction[0]\n",
|
|
" distance = int(instruction[1:])\n",
|
|
"\n",
|
|
" # Calculate final position of the dial\n",
|
|
" if direction == 'R':\n",
|
|
" dial_position = (dial_position + distance) % 100\n",
|
|
" elif direction == 'L':\n",
|
|
" dial_position = (dial_position - distance) % 100\n",
|
|
"\n",
|
|
" return dial_position"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|