Add benchmarks for Vicky on day 3
parent
c73a2ea9d6
commit
3988ef426f
|
|
@ -154,5 +154,14 @@
|
|||
"2-2"
|
||||
],
|
||||
"runs": 1
|
||||
},
|
||||
{
|
||||
"name": "vicky-d03-p1.json",
|
||||
"author": "Vicky",
|
||||
"lang": "Python",
|
||||
"puzzles": [
|
||||
"3-1"
|
||||
],
|
||||
"runs": 1
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
{
|
||||
"results": [
|
||||
{
|
||||
"command": "python vicky_py/d03p1.py",
|
||||
"mean": 0.04658310239999999,
|
||||
"stddev": 0.017986176484155007,
|
||||
"median": 0.04145815832,
|
||||
"user": 0.03983408,
|
||||
"system": 0.006274310800000001,
|
||||
"min": 0.02585583432,
|
||||
"max": 0.09157175432,
|
||||
"times": [
|
||||
0.03625472532,
|
||||
0.03465417832,
|
||||
0.03396654632,
|
||||
0.03618384132,
|
||||
0.04315716032,
|
||||
0.06217007632,
|
||||
0.061074496320000005,
|
||||
0.046393020320000006,
|
||||
0.05460350832000001,
|
||||
0.05359424932000001,
|
||||
0.050319720320000004,
|
||||
0.030011169320000003,
|
||||
0.030839434320000005,
|
||||
0.02988077232,
|
||||
0.03070780932,
|
||||
0.029755778320000002,
|
||||
0.03274030832,
|
||||
0.029488529319999998,
|
||||
0.029114787320000002,
|
||||
0.04140808932,
|
||||
0.07890296532,
|
||||
0.07442519632,
|
||||
0.06510410432000001,
|
||||
0.049949000320000006,
|
||||
0.02817988532,
|
||||
0.03847507932,
|
||||
0.03981689932,
|
||||
0.02994783332,
|
||||
0.04516316732,
|
||||
0.051098552320000004,
|
||||
0.05484034532,
|
||||
0.05636680932,
|
||||
0.05764491832,
|
||||
0.06463834432,
|
||||
0.06740387332,
|
||||
0.06323831732,
|
||||
0.06079315432,
|
||||
0.04869693932,
|
||||
0.025995433320000004,
|
||||
0.026150188320000003,
|
||||
0.02585583432,
|
||||
0.02664621732,
|
||||
0.03747833332,
|
||||
0.04495923332,
|
||||
0.06181685432,
|
||||
0.05188516532000001,
|
||||
0.02641675532,
|
||||
0.03257015632,
|
||||
0.031908224320000005,
|
||||
0.037440533320000004,
|
||||
0.05320423932,
|
||||
0.07328332832000001,
|
||||
0.062135716320000006,
|
||||
0.02798000732,
|
||||
0.02795615932,
|
||||
0.02868359332,
|
||||
0.02806963932,
|
||||
0.029425172319999998,
|
||||
0.05467381032,
|
||||
0.07707768832,
|
||||
0.08245113032000001,
|
||||
0.08727142932000001,
|
||||
0.08412591932,
|
||||
0.03244172632,
|
||||
0.027792763320000004,
|
||||
0.03184680832,
|
||||
0.03138939632,
|
||||
0.03165902632,
|
||||
0.03652552332,
|
||||
0.03918774232,
|
||||
0.03934787932,
|
||||
0.04719080232,
|
||||
0.06493572432,
|
||||
0.055012023320000006,
|
||||
0.08109600032,
|
||||
0.08112990932,
|
||||
0.05461992032,
|
||||
0.026321486320000004,
|
||||
0.03283362032,
|
||||
0.035878437320000005,
|
||||
0.05989386632,
|
||||
0.08422506332,
|
||||
0.04630633932,
|
||||
0.02667289932,
|
||||
0.03158212732,
|
||||
0.03470449432,
|
||||
0.04696434732,
|
||||
0.04663383032,
|
||||
0.02905690732,
|
||||
0.04150822732,
|
||||
0.03999464532,
|
||||
0.027363504320000002,
|
||||
0.038492724320000005,
|
||||
0.04438371432,
|
||||
0.062389057319999996,
|
||||
0.07938231232000001,
|
||||
0.09157175432,
|
||||
0.08544142632,
|
||||
0.048485489320000005,
|
||||
0.02758437332
|
||||
],
|
||||
"exit_codes": [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 84 KiB |
|
|
@ -9,3 +9,9 @@ hyperfine --warmup 5 --export-json data/vicky-d02-p1.json --runs 100 \
|
|||
"python vicky_py/d02p1.py"
|
||||
hyperfine --warmup 5 --export-json data/vicky-d02-p2.json --runs 100 \
|
||||
"python vicky_py/d02p2.py"
|
||||
|
||||
# Benchmark day 3
|
||||
hyperfine --warmup 5 --export-json data/vicky-d03-p1.json --runs 100 \
|
||||
"python vicky_py/d03p1.py"
|
||||
# hyperfine --warmup 5 --export-json data/vicky-d03-p2.json --runs 100 \
|
||||
# "python vicky_py/d03p2.py"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
# # Puzzle 2 of AoC 2025
|
||||
# Author: Victoria Ramírez López
|
||||
#
|
||||
# Date: Dec 3, 2025
|
||||
|
||||
|
||||
# In[59]:
|
||||
|
||||
def calculate_max_joltage(bank = ''):
|
||||
# This function calculates the max joltage
|
||||
# that can be achieved in a battery bank
|
||||
# when turning on 2 batteries
|
||||
# input: bank = String
|
||||
# output: max_joltage = int
|
||||
|
||||
# Create a list containing all the batteries in the bank
|
||||
battery_list = [int(battery) for battery in bank_string]
|
||||
|
||||
# Find the battery with the highest number
|
||||
max_battery = max(battery_list[:-1])
|
||||
max_position = battery_list.index(max_battery)
|
||||
|
||||
if max_position == len(battery_list) - 1:
|
||||
max_joltage = (battery_list[max_position] * 10) + battery_list[-1]
|
||||
else:
|
||||
second_max_battery = max(battery_list[max_position + 1:])
|
||||
second_max_position = battery_list.index(second_max_battery)
|
||||
max_joltage = (battery_list[max_position] * 10) + battery_list[second_max_position]
|
||||
|
||||
return max_joltage
|
||||
|
||||
|
||||
# In[60]:
|
||||
|
||||
# Read input file
|
||||
|
||||
battery_banks = open('../rust/inputs/03.txt', mode ='r') # Open in 'read only' mode
|
||||
|
||||
|
||||
# In[61]:
|
||||
|
||||
# Select 2 batteries per bank to turn on
|
||||
|
||||
max_joltages = []
|
||||
|
||||
for bank in battery_banks:
|
||||
bank_string = bank.strip('\n')
|
||||
if len(bank_string) == 0:
|
||||
continue
|
||||
bank_joltage = calculate_max_joltage(bank_string) # For part 1
|
||||
max_joltages.append(bank_joltage)
|
||||
|
||||
sum_joltages = sum(max_joltages)
|
||||
# print(max_joltages)
|
||||
print(sum_joltages)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue