r/PowerShell • • Dec 04 '25

Advent of code day 3 and 4

Got a bit busy yesterday. I'm currently working on day 3 part 2. How's everyone else coming?

If you don't know what' I'm talking about, it's a coding challenge that runs every december.

https://adventofcode.com/

11 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/Future-Remote-4630 Dec 05 '25

~2 minutes or so, which I was shocked by. The more time I spent, the more of the optimizations I had to remove to get the dang thing to work. I figured at O(N^2) it would have been a nightmare, so I must have either gotten lucky with the dataset or they intentionally have it set up to only require a handful of extra loops to get the new rolls.

My gut says there is probably a really clean solution using matrices and some math, but I've never even started down that road in powershell so I just threw together what I thought would work in concept.

1

u/SrBlackVoid Dec 07 '25

Yeahhh, I was about the same timeframe for Day 4. I'm pretty sure I can still whittle it down by optimizing what gets loop-processed, but I think you're right: the main gains are probably through some matrix math I'm not aware of.