2023 #1

Open
aey wants to merge 22 commits from 2023 into main

22 commits

Author SHA1 Message Date
178d96494a Solve 2023:17 p1-2 "Clumsy Crucible"
Revenge, blast from the past etc!

Had to learn Dijkstra's for this one. Was as stuck
as one can be on AOC. This stopped my progress
2023, and kept me busy at least 20-30h this year
(2024) as well. I never came past part 1, but got
part 2 in minutes when I hit home.

Turns out the initial queue was to blame, after
studying Dijkstras, reading hints on the subreddit
and tutorials in blogs. I was off-by-1 in costs,
since I misplaced a read from the grid.

I also struggled a really, really long time with
a bug where I resetted the steps to aggresively.

What helped me to figure it out was to create
simpler test case grids and step-debug them.

Example 1:

241
321

should give a least heat loss of 6 in pt1.

Example 2:

11199
12199
99199
99131
99111

should give a least heat loss of 9 in pt2.
2025-01-05 00:10:26 +01:00
fb468c2199 Solve 2023:16 "The Floor Will Be Lava" 2025-01-05 00:10:26 +01:00
a90269f7f9 Solve 2023:15 "Lens Library"
WALLOFTEXT for part 2, took me 90 minutes to find
this important text:

> Each step begins with a sequence of letters that
> indicate the label of the lens on which the step
> operates. The result of running the HASH algorithm
> on the label indicates the correct box for that
> step.

It also clarifies how part 2 and part 1 relates.
2025-01-05 00:10:26 +01:00
c832e30dcf Solve 2023:14 "Parabolic Reflector Dish" 2025-01-05 00:10:26 +01:00
3de54ce0e9 Solve 2023:13 "Point of Incidence" 2025-01-05 00:10:26 +01:00
4fa1b1e14c Solve 2023:12 "Hot Springs" 2025-01-05 00:10:26 +01:00
9ca8607f8b Solve 2023:11 "Cosmic Expansion" 2025-01-05 00:10:26 +01:00
a1bf11a5ed Fix flake8 errors for 2023:1-10 2025-01-05 00:10:26 +01:00
b681e5cdb7 Solve 2023:10 "Pipe Maze"
Got completely stuck on part 2. Tried some polygon
area calculations, but none provided the correct
answer, most likely due to the unorthodox polygon
points.

I also tried _shoelace method_ without any luck.
Had not heard about that one earlier, it was a good
learning experience even though I vould not use it
here.

By the subreddit, several people had had luck
using the ray method.

> Part 2 using one of my favorite facts from
> graphics engineering: lets say you have an
> enclosed shape, and you want to color every
> pixel inside of it. How do you know if a given
> pixel is inside the shape or not? Well, it
> turns out: if you shoot a ray in any direction
> from the pixel and it crosses the boundary an
> _odd number_ of times, it's _inside_. if it crosses
> an even number of times, it's outside. Works
> for all enclosed shapes, even self-intersecting
> and non-convex ones.
2025-01-05 00:10:26 +01:00
741f7b89d8 Refactor 2023:05
Increasing speed from 66mins to 4mins. Caching the
location value in the code to keep things at highest
speed.

From the subreddit, the algorithm looks like this.

1. Start att location 0
2. Traverse the whole process backwards, by
   reversing process steps and flipping dest/src
   positions.
3. Output is not a location, instead it's a seed.
4. if seed is in any seed range, use seed to get
   location as in step 1.
5. If not, increase location by 1 and repeat 2-4.
2025-01-05 00:10:26 +01:00
08288964bd Remove parse_input helper 2025-01-05 00:10:26 +01:00
96c4c1383a Solve 2023:09 "Mirage Maintenance" 2025-01-05 00:10:26 +01:00
540fa253da Solve 2023:08 "Haunted Wasteland"
Part 2 would have taken 10-15 hours with brute force.

After I figured out the puzzle input had circular
A-Z paths, it was plain as day that LCM was the
solution to the problem.

https://en.wikipedia.org/wiki/Least_common_multiple
2025-01-05 00:10:26 +01:00
fa3416cf40 Solve 2023:07 "Camel Cards" 2025-01-05 00:10:26 +01:00
a1a69d7114 Solve 2023:06 "Wait for it" 2025-01-05 00:10:26 +01:00
Anders Englöf Ytterström
ad05c8fab4 Solve 2023:05 "If You Give A Seed A Fertilizer"
Part 2 takes 66 minutes to run. There is some smart
things to realize here.
2025-01-05 00:10:26 +01:00
Anders Englöf Ytterström
cbd4bf50e1 Solve 2023:04 "Scratchcards"
On a train that according to swedish tradition
was late. Not a good environment to focus.

Got stuck 2 times:

- Initial code asumed the | was always after the 5th
  number, because of the example. Puzzle input had
  it at pos 10. Classic AoC mistake.
- I had a hard time trying to understand the score
  count, I insisted there was meant to be a +1 at
  some point.

  > That means card 1 is worth 8 points (1 for
  > the first match, then doubled three times for
  > each of the three matches after the first)

I should instead have just looked at the numbers.
2025-01-05 00:10:26 +01:00
7290f28ef7 Solve 2023:03 "Gear Ratios"
Overslept, took about 55 mins.
2025-01-05 00:10:26 +01:00
6001a6bb59 Solve 2023:02 "Cube Conundrum"
Very intermediate pythonic solution,
regex would have made the code more compact.

But since 2023:01 decreased the regex courage,
This code will do.
2025-01-05 00:10:26 +01:00
aae14797ea Solve 2023:01 "Trebuchet?!"
Turns out re methods are non-overlapping. And in
true AoC manners, no provided test cases had
overlaps.

Luckily for me, some of the last lines in the input
contained the string "oneight", so I was able to
find it out quite fast.

Revisions:

1) Reverse strings to find last digit
2) Use isdigit() and skip regex.
3) Use regexp with positive look-ahead.
2025-01-05 00:10:26 +01:00
661f18dca4 Prep Advent of Code 2023 2025-01-05 00:10:26 +01:00
bad86889d6 Revert "2023 solutions (#6)"
This reverts commit b6e048e4a7.
2025-01-05 00:09:28 +01:00