Add day 1 solutions

main
Bram 2025-12-03 22:06:20 +01:00
commit bd8a50df82
49 changed files with 11039 additions and 0 deletions

2
.gitignore vendored
View File

@ -353,6 +353,8 @@ Cargo.lock
*.pdb
# ---> Custom files
bram/benchmarks/sander_hs/bin
brechtje/**/*.txt
# If your structure requires you to ignore certain files or folders,
# you may add them here.

3
bob/README.md Normal file
View File

@ -0,0 +1,3 @@
# AOC 2025
This folder hosts the code written by Bob

36
bob/day01/day01-p1.py Normal file
View File

@ -0,0 +1,36 @@
def dial(action, position):
if action[0] == "R":
position += action[1]
else:
position -= action[1]
position = position % 100
return position
def read_input(filename):
actions = []
for line in open(filename):
line = line.strip()
direction = line[:1]
steps = int(line[1:])
actions.append((direction,steps))
return actions
# filename = "day01/my_example_input"
# filename = "day01/example_input" # Output is 3
filename = "day01/input" # Output is 992
actions = read_input(filename)
position = 50
password = 0
for action in actions:
position = dial(action, position)
if position == 0:
password += 1
print(f"Password is {password}")

44
bob/day01/day01-p2.py Normal file
View File

@ -0,0 +1,44 @@
def dial(action, start_position):
if action[0] == "R":
position = start_position + action[1]
else:
position = start_position - action[1]
# Count rotations over "0" (multiples of 100)
zeros = int(abs(position) / 100)
# Negative position, or exactly "0", caused one extra "0" hit
# Except when starting at 0!
if position <= 0 and start_position != 0:
zeros += 1
position = position % 100
return position, zeros
def read_input(filename):
actions = []
for line in open(filename):
line = line.strip()
direction = line[:1]
steps = int(line[1:])
actions.append((direction,steps))
return actions
# filename = "day01/my_example_input"
# filename = "day01/example_input" # Output is 6
filename = "day01/input" # Output is 6133
actions = read_input(filename)
position = 50
password = 0
for action in actions:
position, zeros = dial(action, position)
password += zeros
print(f"Password is {password}")

10
bob/day01/example_input Normal file
View File

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

4232
bob/day01/input Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,2 @@
L50
L5

File diff suppressed because one or more lines are too long

39
bram/benchmarks/README.md Normal file
View File

@ -0,0 +1,39 @@
# Benchmarking setup
In this folder, I run some benchmarks on everyone's code.
## How to benchmark
1. Make sure you have the appropriate software installed. You can do so by
activating the Nix shell as defined in `shell.nix`, or you can view everyone's
installation requirements in the
[software requirements](#Software-requirements) section.
2. Run benchmarks by executing the respective scripts. For example, if you
wish to benchmark Bram's code, you may run `bram.sh` in your terminal. All data
will be collected in the `data/` folder.
3. Once you have collected all the data you wanted to collect, you can open the
Jupyter Notebook by typing `jupyter notebook Benchmarks.ipynb` in the terminal.
4. In the Jupyter Notebook, evaluate all cells and gain the graphs you want.
Graphs are also stored in the `img/` folder.
## Software requirements
To create the measurements, this benchmarking setup uses
[hyperfine](https://github.com/sharkdp/hyperfine). To build the visualization,
this setup uses [Jupyter Notebooks](https://jupyter.org/) - but you can install
the dependencies listed in `requirements.txt` to get all necessary packages
installed.
Bob uses [Python](https://www.python.org/).
Bram uses [Rust](https://rust-lang.org/) at version 1.86.0.
Brechtje uses [Python](https://www.python.org/).
Sander uses [GHCup](https://www.haskell.org/ghcup/) at version 9.6.7. Haskell
typically opens as a REPL from which functions can be evaluated, so some
liberties are taken here. The script is reformatted in the `sander_hs/` folder
and compiled to a binary in order to approximate performance.

9
bram/benchmarks/bob.sh Normal file
View File

@ -0,0 +1,9 @@
cd ../../bob
# Benchmark day 1
hyperfine --warmup 5 --export-json ../bram/benchmarks/data/bob-d01-p1.json \
--runs 100 "python day01/day01-p1.py"
hyperfine --warmup 5 --export-json ../bram/benchmarks/data/bob-d01-p2.json \
--runs 100 "python day01/day01-p2.py"
cd ../bram/benchmarks

11
bram/benchmarks/bram.sh Normal file
View File

@ -0,0 +1,11 @@
# Move to the appropriate folder
cd ../rust
# Build binary
cargo build --release
# Benchmark day 1
hyperfine --warmup 5 --export-json ../benchmarks/data/bram-d01-100.json \
--runs 100 "for run in {1..100}; do target/release/aoc2025 1; done"
cd ../benchmarks

View File

@ -0,0 +1,13 @@
cd ../../brechtje
# Benchmark day 1
cd 1/
hyperfine --warmup 5 \
--export-json ../../bram/benchmarks/data/brechtje-d01-p1.json \
--runs 100 "python 1-1.py"
hyperfine --warmup 5 \
--export-json ../../bram/benchmarks/data/brechtje-d01-p2.json \
--runs 100 "python 1-2.py"
cd ../
cd ../bram/benchmarks

View File

@ -0,0 +1,29 @@
import json
DIRECTORY = []
with open("data/all.json", "r") as fp:
DIRECTORY = json.load(fp)
def generate_datafile(obj):
path = "data/" + obj["name"]
with open(path, 'r') as fp:
benchmark = json.load(fp)
for time in benchmark["results"][0]["times"]:
yield {
"author": obj["author"],
"lang": obj["lang"],
"time": time / obj["runs"],
}
def generate_day(day : int):
for part in [ 1, 2 ]:
for measurement in generate_puzzle(f"{day}-{part}"):
measurement["part"] = part
yield measurement
def generate_puzzle(puzzle : str):
for obj in DIRECTORY:
if puzzle in obj["puzzles"]:
yield from generate_datafile(obj)

View File

@ -0,0 +1,57 @@
[
{
"name": "bob-d01-p1.json",
"author": "Bob",
"lang": "Python",
"puzzles": [
"1-1"
],
"runs": 1
},
{
"name": "bob-d01-p2.json",
"author": "Bob",
"lang": "Python",
"puzzles": [
"1-2"
],
"runs": 1
},
{
"name": "bram-d01-100.json",
"author": "Bram",
"lang": "Rust",
"puzzles": [
"1-1",
"1-2"
],
"runs": 100
},
{
"name": "brechtje-d01-p1.json",
"author": "Brechtje",
"lang": "Python",
"puzzles": [
"1-1"
],
"runs": 1
},
{
"name": "brechtje-d01-p2.json",
"author": "Brechtje",
"lang": "Python",
"puzzles": [
"1-2"
],
"runs": 1
},
{
"name": "sander-d01-p1.json",
"author": "Sander",
"lang": "Haskell",
"puzzles": [
"1-1"
],
"runs": 1
}
]

View File

@ -0,0 +1,218 @@
{
"results": [
{
"command": "python day01/day01-p1.py",
"mean": 0.018280616970000003,
"stddev": 0.0006054695984127279,
"median": 0.018186844940000002,
"user": 0.01483600999999999,
"system": 0.0033221896000000008,
"min": 0.017335730940000002,
"max": 0.020703820940000003,
"times": [
0.01807126494,
0.01766033694,
0.01770073494,
0.02004624194,
0.018178473940000002,
0.018417852940000003,
0.01812796494,
0.017955673940000003,
0.018379266940000003,
0.01809406594,
0.018453467940000003,
0.01802611594,
0.018267693940000003,
0.01793643794,
0.01828018094,
0.018444996940000003,
0.018143806940000003,
0.019526113940000003,
0.01844583894,
0.019931652940000003,
0.018626267940000003,
0.018122100940000004,
0.018915561940000002,
0.018065865940000002,
0.018375352940000002,
0.019079646940000004,
0.020026991940000002,
0.01761536094,
0.020703820940000003,
0.01825914994,
0.01748083594,
0.01893691494,
0.01743567994,
0.018392330940000003,
0.018382992940000002,
0.018990103940000003,
0.018086712940000003,
0.01733794194,
0.018799991940000003,
0.01816632794,
0.01769464394,
0.01754049594,
0.018241162940000003,
0.017692110940000002,
0.018402830940000003,
0.01799481994,
0.018223985940000003,
0.01759861894,
0.018958858940000003,
0.01837748394,
0.01904514494,
0.01809492294,
0.018427259940000003,
0.01818821094,
0.01813986894,
0.017615985940000002,
0.01796003594,
0.017505334940000002,
0.017965291940000003,
0.017791317940000002,
0.01812525794,
0.01798888094,
0.017678036940000003,
0.01851067694,
0.01800311694,
0.01808681394,
0.018373394940000003,
0.017636636940000002,
0.01763808194,
0.018445332940000003,
0.018159857940000003,
0.017980174940000003,
0.018537869940000003,
0.01955623394,
0.01860408494,
0.018257304940000003,
0.01800734094,
0.018969050940000003,
0.01744151794,
0.01839679694,
0.01871990494,
0.01770890894,
0.01807889994,
0.018185478940000003,
0.01817902994,
0.01770351694,
0.017856927940000003,
0.018366142940000003,
0.017762881940000003,
0.01861377394,
0.018307835940000003,
0.01844301694,
0.017335730940000002,
0.01826272194,
0.018238106940000002,
0.01845287894,
0.01923389294,
0.019019420940000004,
0.01755005494,
0.01829958194
],
"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
]
}
]
}

View File

@ -0,0 +1,218 @@
{
"results": [
{
"command": "python day01/day01-p2.py",
"mean": 0.020615625919999995,
"stddev": 0.0008088849992798855,
"median": 0.02046746494,
"user": 0.017299320000000003,
"system": 0.0031129196,
"min": 0.019567234939999997,
"max": 0.02628018894,
"times": [
0.02120531594,
0.020777152939999998,
0.02165869094,
0.020604701939999998,
0.02084050594,
0.02121598294,
0.02162024094,
0.021570440939999998,
0.02122411594,
0.02059801294,
0.02178862094,
0.02069527294,
0.02011315294,
0.02125525994,
0.02096512494,
0.02085369194,
0.020566496939999998,
0.020334108939999998,
0.020670181939999997,
0.02072439694,
0.02028807694,
0.02055907894,
0.02050522594,
0.02092301294,
0.02069373694,
0.02047648894,
0.019976937939999998,
0.019910852939999998,
0.020397030939999998,
0.020378081939999997,
0.02104977694,
0.02029634894,
0.02018755294,
0.02131716194,
0.019567234939999997,
0.02075919594,
0.01991730294,
0.02038686994,
0.02033121294,
0.01992772394,
0.020304039939999997,
0.01986143994,
0.020572858939999997,
0.020734446939999998,
0.019846204939999997,
0.02002030594,
0.019718745939999997,
0.02024268194,
0.02153054794,
0.02041505394,
0.02017235094,
0.02079594794,
0.01996096494,
0.020180008939999997,
0.02079084694,
0.021043737939999998,
0.019837977939999998,
0.02061569094,
0.02031442194,
0.02030791894,
0.019852781939999998,
0.020351002939999998,
0.020259908939999998,
0.02053684794,
0.02018773594,
0.01992955094,
0.02045844094,
0.01992390594,
0.020803037939999998,
0.02061347694,
0.02014947494,
0.020152006939999998,
0.02034143394,
0.01983471794,
0.020450447939999998,
0.022272646939999998,
0.02044323294,
0.020688650939999997,
0.020061243939999997,
0.020233437939999998,
0.020981132939999998,
0.019957915939999998,
0.02051775194,
0.01970484894,
0.02035442294,
0.019966405939999998,
0.02193963894,
0.02078478494,
0.02628018894,
0.02180391294,
0.020251498939999998,
0.02187088094,
0.020118542939999998,
0.021709151939999997,
0.02086194094,
0.01997328994,
0.020484386939999998,
0.021529263939999998,
0.019873743939999997,
0.02065833294
],
"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
]
}
]
}

View File

@ -0,0 +1,218 @@
{
"results": [
{
"command": "for run in {1..100}; do target/release/aoc2025 1; done",
"mean": 0.10949902425999998,
"stddev": 0.01303120138107424,
"median": 0.10794122648000001,
"user": 0.0481385,
"system": 0.06004530999999999,
"min": 0.08743557148000002,
"max": 0.14346140548,
"times": [
0.10262904248000002,
0.10309315948000002,
0.08788191948000001,
0.08788880848000001,
0.08988906048000002,
0.08751818448000001,
0.08957111248,
0.09758415848000002,
0.09701446348000001,
0.09691613148000001,
0.09622675148000001,
0.09456499148000001,
0.09579022648000002,
0.09444151848000001,
0.09508792248000002,
0.09606605248000001,
0.09695228048000001,
0.09945660648000001,
0.09628507748000001,
0.09672642548000002,
0.09634512948000001,
0.09588621348000001,
0.09470692948000001,
0.09532162748000002,
0.09455080948000001,
0.09497292148000001,
0.10120339848000001,
0.11154805048000001,
0.11532427548000002,
0.12480157548000002,
0.12592739948,
0.12507496648,
0.12549518748,
0.12522092848,
0.12732470448,
0.12790656448,
0.12489098348000001,
0.13339627348,
0.10624044648000001,
0.10724894148000001,
0.10669420748000001,
0.10763329948000001,
0.10534154348000001,
0.10543322348000002,
0.10665542748000001,
0.10487852848000001,
0.10716879648000001,
0.11600640648000002,
0.11622806648000002,
0.11648707548000001,
0.11719899848000001,
0.11843976248000002,
0.08857608548000001,
0.09061829048000002,
0.08743557148000002,
0.10892493048000002,
0.11079558148000002,
0.11606146848000001,
0.12125704848000002,
0.12159368348000002,
0.11949176648000001,
0.11928547748000001,
0.12190114648000001,
0.12102119648000001,
0.12058027548000001,
0.12061425148000002,
0.12009168948000001,
0.12136069848000001,
0.12952496048,
0.09928884548000001,
0.09773379248000001,
0.09590983548000001,
0.10297853048000001,
0.11318080748000002,
0.11342295148000002,
0.11455993448000001,
0.11295701548000002,
0.11299484748000001,
0.11239145748000001,
0.11219660648000002,
0.11406977448000001,
0.11238566648000001,
0.11289772048000002,
0.11166642748000001,
0.12329825748000002,
0.12529479848,
0.13912101548,
0.14346140548,
0.14263528748,
0.12373552048000001,
0.10561196548000001,
0.10513752748,
0.10701318248000001,
0.10513885148000002,
0.10542516148000002,
0.10548880248000002,
0.10595660348000001,
0.10824915348000001,
0.11516850448000002,
0.12826149748000001
],
"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
]
}
]
}

View File

@ -0,0 +1,218 @@
{
"results": [
{
"command": "python 1-1.py",
"mean": 0.01843302404,
"stddev": 0.0012657147339510022,
"median": 0.017979195580000003,
"user": 0.015601169999999998,
"system": 0.002655909,
"min": 0.01719525558,
"max": 0.024262817580000005,
"times": [
0.021940215580000005,
0.02037590558,
0.01956901858,
0.01847677558,
0.017818465580000005,
0.017927290580000005,
0.01987165758,
0.017643502580000005,
0.01889718958,
0.017678766580000005,
0.01798546058,
0.01796282558,
0.018096614580000003,
0.019076076580000004,
0.017984125580000003,
0.01791695258,
0.01766349558,
0.02018217858,
0.01855690058,
0.01782171658,
0.018275047580000002,
0.01793372058,
0.018170532580000003,
0.017849274580000005,
0.01762079558,
0.01847150358,
0.017508063580000004,
0.017649895580000005,
0.01746609658,
0.017974265580000003,
0.01829079258,
0.01731760458,
0.01785077358,
0.01721457758,
0.01787336758,
0.018715130580000003,
0.017604400580000006,
0.01719525558,
0.01837595358,
0.019775062580000002,
0.017288543580000003,
0.017996394580000005,
0.017708625580000005,
0.01723078058,
0.01859565758,
0.017730976580000002,
0.017462975580000005,
0.017829121580000003,
0.01851731458,
0.01785272158,
0.01804898958,
0.017888834580000006,
0.01731304058,
0.017909111580000005,
0.018421691580000003,
0.017520087580000003,
0.01780653158,
0.017915070580000005,
0.01786583858,
0.017567218580000002,
0.018018454580000003,
0.01769244358,
0.018978892580000004,
0.01816111358,
0.017368446580000002,
0.017602324580000002,
0.01786462758,
0.01852068958,
0.018079517580000003,
0.01744804658,
0.017847348580000005,
0.01761715958,
0.01768220458,
0.017716536580000004,
0.017590534580000004,
0.01916825858,
0.01837094258,
0.024262817580000005,
0.023162718580000005,
0.02013178158,
0.022817841580000005,
0.019455812580000002,
0.018663137580000003,
0.020078744580000002,
0.018950286580000003,
0.022046223580000003,
0.01906816058,
0.01824326458,
0.01871615058,
0.01788724858,
0.018833006580000006,
0.01850424658,
0.020043292580000004,
0.01800679058,
0.01962254158,
0.017958190580000005,
0.018563434580000003,
0.01756514958,
0.017695261580000003,
0.018251983580000006
],
"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
]
}
]
}

View File

@ -0,0 +1,218 @@
{
"results": [
{
"command": "python 1-2.py",
"mean": 0.10065511542000002,
"stddev": 0.005070299601528213,
"median": 0.10021386182000001,
"user": 0.09656875,
"system": 0.003348090000000002,
"min": 0.08970616732000002,
"max": 0.12020687432000002,
"times": [
0.09720221832,
0.09865108932000001,
0.09526603432000001,
0.10220708232000002,
0.10600740832000001,
0.09565718732000002,
0.09584613332000001,
0.10399513632000001,
0.10715478232000002,
0.10124971932000001,
0.10037107232000002,
0.10223235032000001,
0.09968424232,
0.09940458732000002,
0.09930831532,
0.09532145232000001,
0.08970616732000002,
0.09986469332000002,
0.09213563732,
0.09521426632,
0.10171789432000002,
0.09781683532000002,
0.10088793532000001,
0.10186061832000001,
0.09871522032,
0.10478594232,
0.09268426532000001,
0.11021149432,
0.10253815832000002,
0.09696197432,
0.09825557732000001,
0.10135564132000001,
0.10723291232000001,
0.09486173832000001,
0.12020687432000002,
0.10346667332000001,
0.09620447132000001,
0.10211980332000001,
0.10263448232000001,
0.09739181032000001,
0.10659001632000001,
0.09343680432000001,
0.10017148632000002,
0.09568633732000001,
0.10377575732000001,
0.10569169432000002,
0.09891529332000001,
0.09706895132000001,
0.10359639532,
0.11909498532000001,
0.10124096632000001,
0.10726747332000001,
0.09666090032,
0.10025623732000001,
0.09513318232000001,
0.10827525632000001,
0.10478741132000001,
0.09365811832000001,
0.09568155632000001,
0.10111659732000002,
0.10849375632000001,
0.10122607432000001,
0.09808621332000002,
0.10768904532000001,
0.09773930432000001,
0.10163057132000002,
0.09868030232000001,
0.10004012732,
0.09432664032000002,
0.09809490532000001,
0.09813455632000001,
0.10013154632000001,
0.10039868432000001,
0.09614563532,
0.09835838332,
0.09961064332000001,
0.10083732132,
0.10392489432000002,
0.10173207032,
0.09681472732000002,
0.09998077132000001,
0.10510356132000001,
0.10299731132,
0.09985206932000001,
0.10440825632000002,
0.10392704632000001,
0.10417230732000002,
0.10073995232,
0.10120393632000001,
0.10234714332000001,
0.09503944032000002,
0.09673561932000001,
0.10741705832000001,
0.11105290632,
0.09754221632000001,
0.10467473532000002,
0.09256150232000002,
0.09705440132000001,
0.10414729132000002,
0.09596329532000002
],
"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
]
}
]
}

View File

@ -0,0 +1,218 @@
{
"results": [
{
"command": "sander_hs/bin/d01-p1",
"mean": 0.022359646950000003,
"stddev": 0.003947930999644063,
"median": 0.0221566094,
"user": 0.011003309999999999,
"system": 0.0036034243999999997,
"min": 0.011151118400000002,
"max": 0.0418797714,
"times": [
0.021608108400000003,
0.0216550764,
0.0214301634,
0.0217091644,
0.021845091400000002,
0.0218199154,
0.0219022274,
0.0222604954,
0.0221990744,
0.0221290354,
0.022109658400000003,
0.0221543054,
0.0220385414,
0.0221145864,
0.0222324194,
0.0222197784,
0.022081751400000002,
0.0221985664,
0.0221589134,
0.022402793400000003,
0.022002303400000003,
0.022110325400000002,
0.0219013264,
0.022116461400000002,
0.021828275400000003,
0.021764728400000002,
0.0218213174,
0.011151118400000002,
0.021338464400000003,
0.0224858174,
0.04095669340000001,
0.023139116400000003,
0.022919120400000003,
0.0401848994,
0.023492082400000003,
0.0235819404,
0.0233865764,
0.023311378400000003,
0.0237322984,
0.023424249400000003,
0.023000724400000002,
0.0230065454,
0.0218798444,
0.0218653774,
0.021647235400000003,
0.022240412400000003,
0.0224920394,
0.0223583574,
0.0223172124,
0.0220545844,
0.011460039400000002,
0.012014767400000001,
0.011425214400000001,
0.022288648400000003,
0.0214406644,
0.021533019400000002,
0.022723869400000003,
0.0418797714,
0.023123074400000002,
0.022699171400000002,
0.022425212400000002,
0.0225628434,
0.0217416164,
0.021699208400000003,
0.0221595004,
0.022477877400000002,
0.0222780814,
0.0225413564,
0.0223755154,
0.021824677400000003,
0.021797454400000003,
0.021913774400000002,
0.0218400794,
0.022196666400000002,
0.022422626400000003,
0.0221716494,
0.022310612400000002,
0.022924382400000002,
0.023227522400000002,
0.022039313400000003,
0.021584635400000003,
0.0217211544,
0.021672446400000003,
0.0218050724,
0.0217344044,
0.0223603214,
0.0224140354,
0.0225898824,
0.022544186400000003,
0.022495991400000002,
0.022461002400000003,
0.022642661400000003,
0.0216293234,
0.021656978400000002,
0.0217763664,
0.021687655400000002,
0.0218970694,
0.021596916400000003,
0.0222494804,
0.0221464094
],
"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.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -0,0 +1,16 @@
backports.tarfile==1.2.0
chardet==5.2.0
fqdn==1.5.1
html5lib==1.1
importlib-metadata==8.0.0
isoduration==20.11.0
jaraco.collections==5.1.0
jsonpointer==3.0.0
notebook==7.4.1
pip-chill==1.0.2
seaborn==0.13.2
tinycss2==1.4.0
toml==0.10.2
tomli==2.0.1
uri-template==1.3.0
webcolors==24.11.1

View File

@ -0,0 +1,7 @@
# Build binaries
ghc -O2 sander_hs/d01p1.hs -o sander_hs/bin/d01-p1
# Benchmark day 1
hyperfine --warmup 5 --export-json data/sander-d01-p1.json --runs 100 \
"sander_hs/bin/d01-p1"

View File

@ -0,0 +1,40 @@
import System.IO
import Control.Monad
main :: IO()
main = do handle <- openFile "../rust/inputs/01.txt" ReadMode
contents <- hGetContents handle
print (doday1_1 contents)
hClose handle
-- Day 1: ...
-- Part One (correct)
doday1_1 :: String -> String
doday1_1 input = show (countZeroRotations (words input) 50)
countZeroRotations :: [String] -> Int -> Int
countZeroRotations [] _ = 0
countZeroRotations (x : xs) pos = countZeroRotations xs (fst (rotateDial x pos)) + snd (rotateDial x pos)
rotateDial :: String -> Int -> (Int, Int)
rotateDial (direction : r) pos
| direction == 'L' && newposl == 0 = (normalizeHundred newposl, 1)
| direction == 'L' = (normalizeHundred newposl, 0)
| direction == 'R' && newposr == 0 = (normalizeHundred newposr, 1)
| direction == 'R' = (normalizeHundred newposr, 0)
where newposl = normalizeHundred (pos - (read r))
newposr = normalizeHundred (pos + (read r))
normalizeHundred :: Int -> Int
normalizeHundred x
| x >= 0 && x < 100 = x
| x >= 100 = normalizeHundred (x - 100)
| x < 0 = normalizeHundred (x + 100)
| True = x
-- Part Two
doday1_2 :: String -> String
doday1_2 input = undefined

30
bram/benchmarks/shell.nix Normal file
View File

@ -0,0 +1,30 @@
let
pkgs = import <nixpkgs> {};
in pkgs.mkShell {
packages = with pkgs; [
# Benchmarking tool
hyperfine
# Haskell
haskell.compiler.native-bignum.ghc967
# Jupyter notebook
(python312.withPackages
(py-pkgs: with py-pkgs; [
matplotlib
notebook
pandas
pip-chill
seaborn
])
)
];
# Rust installation
nativeBuildInputs = with pkgs; [ rustc cargo gcc rustfmt clippy valgrind ];
# Certain Rust tools won't work without this
# This can also be fixed by using oxalica/rust-overlay and specifying the rust-src extension
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/3?u=samuela. for more details.
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}

1
bram/rust/.envrc Normal file
View File

@ -0,0 +1 @@
use nix

8
bram/rust/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "aoc2025"
version = "0.1.0"
edition = "2024"
[dependencies]
colored = "3.0.0"
regex = "1.12.2"

4543
bram/rust/inputs/01.txt Normal file

File diff suppressed because it is too large Load Diff

0
bram/rust/inputs/02.txt Normal file
View File

0
bram/rust/inputs/03.txt Normal file
View File

0
bram/rust/inputs/04.txt Normal file
View File

0
bram/rust/inputs/05.txt Normal file
View File

0
bram/rust/inputs/06.txt Normal file
View File

0
bram/rust/inputs/07.txt Normal file
View File

0
bram/rust/inputs/08.txt Normal file
View File

0
bram/rust/inputs/09.txt Normal file
View File

0
bram/rust/inputs/10.txt Normal file
View File

0
bram/rust/inputs/11.txt Normal file
View File

0
bram/rust/inputs/12.txt Normal file
View File

9
bram/rust/shell.nix Normal file
View File

@ -0,0 +1,9 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [ rustc cargo gcc rustfmt clippy valgrind ];
# Certain Rust tools won't work without this
# This can also be fixed by using oxalica/rust-overlay and specifying the rust-src extension
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/3?u=samuela. for more details.
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}

View File

@ -0,0 +1,67 @@
use crate::utils;
struct Dial {
points_at : i16,
clicks : u32,
passing_clicks : u32,
}
impl Dial {
fn new() -> Dial {
Dial { points_at : 50, clicks : 0, passing_clicks : 0 }
}
fn rotate_by(&mut self, r : i16) -> () {
let start : i16 = self.points_at;
self.points_at += r;
self.points_at = self.points_at.rem_euclid(100);
self.passing_clicks += (r.abs() / 100) as u32;
if self.points_at == 0 {
self.clicks += 1;
// Avoid double counting when starting and landing on zero
if r / 100 != 0 && r % 100 == 0 {
self.passing_clicks -= 1;
}
}
if r < 0 && start < self.points_at && start != 0 {
self.passing_clicks += 1;
}
if r > 0 && start > self.points_at && self.points_at != 0 {
self.passing_clicks += 1;
}
// println!(
// "Dial {} now points at {} ({} clicks, {} passing)",
// r, self.points_at, self.clicks, self.passing_clicks
// );
}
}
pub fn answer(text : String) ->( u32, u32 ) {
let mut dial : Dial = Dial::new();
for d in text.split("\n").filter_map(str_to_dir) {
dial.rotate_by(d);
}
( dial.clicks
, dial.clicks + dial.passing_clicks
)
}
fn str_to_dir(s : &str) -> Option<i16> {
if s.len() < 2 {
return None;
}
let (dir, l) : (&str, &str) = s.split_at(1);
match dir {
"L" => Some(-1 * utils::str_to_i16(l)?),
"R" => utils::str_to_i16(l),
_ => None,
}
}

90
bram/rust/src/lib.rs Normal file
View File

@ -0,0 +1,90 @@
mod day_01;
// mod day_02;
// mod day_03;
// mod day_04;
// mod day_05;
// mod day_06;
// mod day_07;
// mod day_08;
// mod day_09;
// mod day_10;
// mod day_11;
mod utils;
use std::time::Duration;
use crate::utils::read_from_file;
use crate::utils::diagnostics;
pub type DailyOutput = ( u128, u128, Duration );
pub use crate::utils::diagnostics::AdventOfCode;
pub fn day_01() -> DailyOutput {
let s : String = read_from_file("inputs/01.txt");
let ( p1, p2, d ) = diagnostics::benchmark(s, day_01::answer);
( p1 as u128, p2 as u128, d )
}
// pub fn day_02() -> DailyOutput {
// let s : String = read_from_file("inputs/02.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_02::answer);
// ( p1 as u128, p2 as u128, d )
// }
// pub fn day_03() -> DailyOutput {
// let s : String = read_from_file("inputs/03.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_03::answer);
// ( p1 as u128, p2 as u128, d )
// }
// pub fn day_04() -> DailyOutput {
// let s : String = read_from_file("inputs/04.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_04::answer);
// ( p1 as u128, p2 as u128, d )
// }
// pub fn day_05() -> DailyOutput {
// let s : String = read_from_file("inputs/05.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_05::answer);
// ( p1 as u128, p2 as u128, d )
// }
// pub fn day_07() -> DailyOutput {
// let s : String = read_from_file("inputs/07.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_07::answer);
// ( p1 as u128, p2 as u128, d )
// }
// pub fn day_08() -> DailyOutput {
// let s : String = read_from_file("inputs/08.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_08::answer);
// ( p1 as u128, p2 as u128, d )
// }
// pub fn day_09() -> DailyOutput {
// let s : String = read_from_file("inputs/09.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_09::answer);
// ( p1 as u128, p2 as u128, d )
// }
// pub fn day_10() -> DailyOutput {
// let s : String = read_from_file("inputs/10.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_10::answer);
// ( p1 as u128, p2 as u128, d )
// }
// pub fn day_11() -> DailyOutput {
// let s : String = read_from_file("inputs/11.txt");
// let (p1, p2, d) = diagnostics::benchmark(s, day_11::answer);
// ( p1 as u128, p2 as u128, d )
// }

52
bram/rust/src/main.rs Normal file
View File

@ -0,0 +1,52 @@
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() > 1 {
let day : Option<u8> = args[1].parse().ok();
match day {
Some(1) => run_day(aoc2025::day_01),
// Some(2) => run_day(aoc2025::day_02),
// Some(3) => run_day(aoc2025::day_03),
// Some(4) => run_day(aoc2025::day_04),
// Some(5) => run_day(aoc2025::day_05),
// Some(6) => run_day(aoc2025::day_06),
// Some(7) => run_day(aoc2025::day_07),
// Some(8) => run_day(aoc2025::day_08),
// Some(9) => run_day(aoc2025::day_09),
// Some(10) => run_day(aoc2025::day_10),
// Some(11) => run_day(aoc2025::day_11),
// Some(12) => run_day(aoc2025::day_12),
Some(_) => run_all_days(),
None => run_all_days(),
}
} else {
run_all_days();
}
}
fn run_all_days() {
let mut aoc = aoc2025::AdventOfCode::new();
aoc.insert(1, aoc2025::day_01());
// aoc.insert(2, aoc2025::day_02());
// aoc.insert(3, aoc2025::day_03());
// aoc.insert(4, aoc2025::day_04());
// aoc.insert(5, aoc2025::day_05());
// aoc.insert(6, aoc2025::day_06());
// aoc.insert(7, aoc2025::day_07());
// aoc.insert(8, aoc2025::day_08());
// aoc.insert(9, aoc2025::day_09());
// aoc.insert(10, aoc2025::day_10());
// aoc.insert(11, aoc2025::day_11());
// aoc.insert(12, aoc2025::day_12());
aoc.show_diagnostics();
}
fn run_day(day : fn() -> aoc2025::DailyOutput) {
let (p1, p2, _) = day();
println!("Part 1: {}", p1);
println!("Part 2: {}", p2);
}

View File

@ -0,0 +1,100 @@
use colored::Colorize;
use std::time::{Duration, Instant};
const MAX_MS_ON_SCREEN : u128 = 100;
const BAR_WIDTH_UNIT : f32 = 10.0;
pub struct AdventOfCode {
days : [ Option<DayResults>; 12 ],
}
impl AdventOfCode {
pub fn insert(&mut self, i : usize, (p1, p2, d ) : ( u128, u128, Duration )) {
self.days[i - 1] = Some(
DayResults{ part_1 : p1, part_2 : p2, duration : d }
);
}
pub fn new() -> AdventOfCode {
AdventOfCode{
// If I don't do it like this, the compiler wants me to define
// the Copy trait for the DayResults struct.
days : [
None, None, None, None,
None, None, None, None,
None, None, None, None,
]
}
}
pub fn show_diagnostics(&self) {
println!("| | {: ^15} | {: ^15} | Duration |",
"Part 1", "Part 2"
);
let total : u128 = self.days
.iter()
.enumerate()
.map(|(day, result)| {
match result {
Some(r) => {
println!("{}", r.to_string(day + 1, MAX_MS_ON_SCREEN));
r.duration.as_millis()
},
None => {
println!("{}", empty_diagnostic(day + 1));
0
},
}
})
.sum();
println!("");
println!("Total duration: {total} ms");
}
}
struct DayResults {
part_1 : u128,
part_2 : u128,
duration : Duration,
}
impl DayResults {
fn to_string(&self, day : usize, max_duration : u128) -> String {
let duration = self.duration.as_millis();
let fraction = duration as f32 / max_duration as f32;
let g = horizontal_bar('#', ' ', 4.0 * BAR_WIDTH_UNIT * fraction, 2.0 * BAR_WIDTH_UNIT);
let o = horizontal_bar('#', ' ', 4.0 * BAR_WIDTH_UNIT * (fraction - 0.50), BAR_WIDTH_UNIT);
let r = horizontal_bar('#', ' ', 4.0 * BAR_WIDTH_UNIT * (fraction - 0.75), BAR_WIDTH_UNIT);
format!(
"| Day {: >2} | {: >15} | {: >15} | {: >6}ms | [{: <}{: <6}{: <6}",
day, self.part_1, self.part_2, self.duration.as_millis(),
g.as_str().green(), o.as_str().yellow(), r.as_str().red()
)
}
}
pub fn benchmark<A,B>(s : String, f : fn(String) -> ( A, B )) -> ( A, B, Duration ) {
let now = Instant::now();
let ( a, b ) = f(s);
( a, b, now.elapsed() )
}
fn empty_diagnostic(day : usize) -> String {
format!("| Day {: >2} | {:->15} | {:->15} | {:->8} | [", day, "", "", "")
}
fn horizontal_bar(full : char, empty : char, width : f32, max_width : f32) -> String {
(0..(max_width.floor() as u32))
.map(|w| {
if (w as f32) < width {
full
} else {
empty
}
})
.collect()
}

View File

@ -0,0 +1,41 @@
use std::fs;
pub mod diagnostics;
// pub fn char_to_u64(s : char) -> Option<u64> {
// s.to_string().parse::<u64>().ok()
// }
pub fn read_from_file(name : &str) -> String {
match fs::read_to_string(name) {
Err(error) => {
println!("Failed to read file {name}: {error}");
String::new()
},
Ok(s) => s,
}
}
pub fn str_to_i16(s : &str) -> Option<i16> {
s.trim().to_string().parse::<i16>().ok()
}
// pub fn str_to_i32(s : &str) -> Option<i32> {
// s.trim().to_string().parse::<i32>().ok()
// }
// pub fn str_to_u8(s : &str) -> Option<u8> {
// s.trim().to_string().parse::<u8>().ok()
// }
// pub fn str_to_u16(s : &str) -> Option<u16> {
// s.trim().to_string().parse::<u16>().ok()
// }
// pub fn str_to_u32(s : &str) -> Option<u32> {
// s.trim().to_string().parse::<u32>().ok()
// }
// pub fn str_to_u64(s : &str) -> Option<u64> {
// s.trim().to_string().parse::<u64>().ok()
// }

22
brechtje/1/1-1.py Normal file
View File

@ -0,0 +1,22 @@
input = open("input.txt", "r").read().splitlines()
pos = 50
password = 0
for line in input:
if line.startswith('L'):
pos -= int(line[1:])
elif line.startswith('R'):
pos += int(line[1:])
# keep subtracting or adding 100 until position is between 0 and 99
while pos < 0 or pos > 99:
if pos < 0:
pos += 100
elif pos > 99:
pos -= 100
if pos == 0:
password += 1
print(password)

21
brechtje/1/1-2.py Normal file
View File

@ -0,0 +1,21 @@
input = open("input.txt", "r").read().splitlines()
pos = 50
password = 0
for line in input:
if line.startswith('L'):
for _ in range(int(line[1:])):
pos -= 1
if pos == -1:
pos = 99
elif pos == 0:
password += 1
elif line.startswith('R'):
for _ in range(int(line[1:])):
pos += 1
if pos == 100:
pos = 0
password += 1
print(password)

51
sander/AoC 2025 Normal file
View File

@ -0,0 +1,51 @@
-- AOC 2025 - Sander
-- so for those wondering about how I run this Haskell code, here's the setup:
-- 1) install GHCup as instructed from https://www.haskell.org/ghcup/
-- 2) save this haskell file and your AOC input file in some directory on your computer
-- 3) rewrite the "main" function with the location of your AOC input file
-- 4) rewrite "print contents" in the "main" function to use the function(s) you've made to process the input file ("contents") from that day correctly
-- 5) run Command Prompt, go to the directory of your files (with "cd" command) and run the command "ghci AOC2025.hs"
-- 6) run command "main"
-- 7) if your functions are correct, you'll get the correct answer!
import System.IO
import Control.Monad
main :: IO()
main = do handle <- openFile "C:/Users/[your directory here]/d1.txt" ReadMode
contents <- hGetContents handle
print (doday1_1 contents)
hClose handle
-- Day 1: ...
-- Part One (correct)
doday1_1 :: String -> String
doday1_1 input = show (countZeroRotations (words input) 50)
countZeroRotations :: [String] -> Int -> Int
countZeroRotations [] _ = 0
countZeroRotations (x : xs) pos = countZeroRotations xs (fst (rotateDial x pos)) + snd (rotateDial x pos)
rotateDial :: String -> Int -> (Int, Int)
rotateDial (direction : r) pos
| direction == 'L' && newposl == 0 = (normalizeHundred newposl, 1)
| direction == 'L' = (normalizeHundred newposl, 0)
| direction == 'R' && newposr == 0 = (normalizeHundred newposr, 1)
| direction == 'R' = (normalizeHundred newposr, 0)
where newposl = normalizeHundred (pos - (read r))
newposr = normalizeHundred (pos + (read r))
normalizeHundred :: Int -> Int
normalizeHundred x
| x >= 0 && x < 100 = x
| x >= 100 = normalizeHundred (x - 100)
| x < 0 = normalizeHundred (x + 100)
| True = x
-- Part Two
doday1_2 :: String -> String
doday1_2 input = undefined