Merge Vicky's branch into benchmark branch

bram-benchmarks
Bram 2025-12-03 18:20:16 +01:00
commit 9eff6e92d4
9 changed files with 4880 additions and 0 deletions

2
vicky/README.md Normal file
View File

@ -0,0 +1,2 @@
# Vicky's AoC folder
Welcome to my branch! :D

99
vicky/dec1/dec1.ipynb Normal file
View File

@ -0,0 +1,99 @@
{
"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
}

50
vicky/dec1/dec1.py Normal file
View File

@ -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

View File

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

4387
vicky/dec1/input_dec1.txt Normal file

File diff suppressed because it is too large Load Diff

194
vicky/dec2/dec2.ipynb Normal file

File diff suppressed because one or more lines are too long

136
vicky/dec2/dec2.py Normal file
View File

@ -0,0 +1,136 @@
#!/usr/bin/env python
# coding: utf-8
# # Puzzle 2 of AoC 2025
# Author: Victoria Ramírez López
#
# Date: Dec 2, 2025
# In[49]:
# Read product ID ranges file
import csv
input_file = open('product_id_ranges.txt', mode ='r') # Open in 'read only' mode
id_ranges_csv = csv.reader(input_file)
id_ranges_list = list(id_ranges_csv)
# In[52]:
# Get invalid ids and calculate answer
invalid_ids = []
id_ranges = []
for id_range in id_ranges_list[0]:
# invalid_ids_range = find_invalid_ids(id_range) # For part 1 answer
invalid_ids_range = find_all_invalid_ids(id_range) # For part 2 answer
invalid_ids.append(invalid_ids_range[:])
sum_invalid_ids = sum(sum(invalid_ids,[]))
# print(invalid_ids)
print(sum_invalid_ids)
# In[18]:
def find_invalid_ids(id_range=''):
# This function finds the invalid ids within the specified range (part 1)
# input: id_range = String
# output: invalid_ids = int []
invalid_ids = []
invalid_id = []
# Extract the upper and lower bounds of the range
lb = int(id_range.split('-')[0])
ub = int(id_range.split('-')[1]) + 1
# Generate the series of product ids withing the range
product_ids = range(lb,ub)
# Find invalid ids
for id in product_ids:
id_string = str(id) # Convert each product id to string
if len(id_string) % 2 == 0:
middle_point = len(id_string) // 2 # Find where to split the product id in 2
# Compare the two halves of the id to determine if the id is invalid
first_half = id_string[0:middle_point]
second_half = id_string[middle_point:]
if first_half == second_half: # If the two halves are equal, the id is invalid
invalid_id = int(id_string)
invalid_ids.append(invalid_id)
return invalid_ids
# In[51]:
def find_all_invalid_ids(id_range=''):
# This function finds all the invalid ids within the specified range (part 2)
# input: id_range = String
# output: invalid_ids = int [[]]
invalid_ids = []
invalid_id = []
# Extract the upper and lower bounds of the range
lb = int(id_range.split('-')[0])
ub = int(id_range.split('-')[1]) + 1
# Generate the series of product ids withing the range
product_ids = range(lb,ub)
# Find invalid ids
for id in product_ids:
id_string = str(id) # Convert each product id to string
chopped_ids = chop_product_id(id) # Chop each product id into equal-sized pieces
# Identify ids with a repeating pattern
for list in chopped_ids:
chunks_set = set(list) # Convert each group of equal-sized chunks into a set
if len(chunks_set) == 1: # If the resulting set has only 1 element, the id is invalid
invalid_id = int(id_string)
invalid_ids.append(invalid_id)
break
return(invalid_ids)
# In[33]:
def chop_product_id(id):
# This function chops a product id into chunks of equal sizes
# input: id = int
# output: chopped_id = [[]]
id_string = str(id)
chunks = []
chopped_id = []
# Find divisors to split the id into equal-sized chunks
# (aka: how many ways to split the id into equal-sized chunks are there?)
for divisor in range(2,len(id_string) + 1):
if len(id_string) % divisor == 0:
chunks = []
chunk_size = len(id_string) // divisor # Determine how big a chunk would be
for i in range(1,len(id_string)+1,chunk_size): # Chop the id
chunk = id_string[i-1:(i-1 + chunk_size)]
chunks.append(chunk)
chopped_id.append(chunks)
return chopped_id

View File

@ -0,0 +1 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124

View File

@ -0,0 +1 @@
959516-995437,389276443-389465477,683-1336,15687-26722,91613-136893,4-18,6736-12582,92850684-93066214,65-101,6868676926-6868700146,535033-570760,826141-957696,365650-534331,1502-2812,309789-352254,79110404-79172400,18286593-18485520,34376-65398,26-63,3333208697-3333457635,202007-307147,1859689-1936942,9959142-10053234,2318919-2420944,5142771457-5142940464,1036065-1206184,46314118-46413048,3367-6093,237-481,591751-793578