Commit graph

18 commits

Author SHA1 Message Date
d02f63a4ef Solve 2016:22 p2 "Grid Computing"
Solved by hand by visualizing the filesystem as
a grid, and put into a simple formula.

In Sweden, this is called a "Femtonspel".
https://sv.wikipedia.org/wiki/Femtonspel
2024-12-12 13:53:43 +01:00
8aa6363b9f Solve 2016:25 p1 "Clock Signal"
Did brute force, but earlier drafts of the code
failed to exit the while loop correcly.

By manual testing, an odd number is required in reg
a to set the first output to 0 (for my puzzle
input at least). Hence, only odd numbers are tested.
2024-12-12 13:53:43 +01:00
abaec4231f Solve 2016:24 p1-2 "Air Duct Spelunking"
BFS baby.
2024-12-12 13:53:43 +01:00
525c6aa96c Solve 2016:23 p1-2 "Safe Cracking"
Solution cide works, but is slow. According to the
subreddit, pt 2 is meant to be an exercise in
optimization.

Turns out the assembly instructions do a factorial,
i.e 7! and 12! and adds a salt (5840).

Got that spoiled. :)
2024-12-12 13:53:43 +01:00
c33bdc3f02 Solve 2016:22 p1 "Grid Computing"
Pt 2 are meant to solved by hand. Will do that
from the print I got.
2024-12-12 13:53:43 +01:00
e75670eaf2 Solve 2016:21 p1-2 "Scrambled Letters and Hash"
A good day to utilize lots of unit testing!

For pt 2, the code initially tried to reverse
the scramble algorithm. The final code however
got the unscrambled version by the traditional
method most password crackers would resolve to:
basic brute forcing with permutations as a list
of candidates.
2024-12-12 13:53:43 +01:00
63da79b2a4 Solve 2016:20 p1-2 "Firewall Rules"
The code at one time used cached responses for
in range bools, but it seems that does not improve
performance.

Some IP addresses are allowed multiple times, so
min() and set() are used to find the distinct
values.
2024-12-12 13:53:43 +01:00
39e09dd36e Solve 2016:19 p1-2 "An Elephant Named Joseph"
Learned a lot about the Josephus' Problem today!

Solved part 1 by using a dict, but eventually
ended up just adding the mathematical shortcut
and rewriting both parts to use deque() for
performance.

Part 2 was tricky, since k (the elf to remove
after all presents were stolen from them) is a
index that changes over time. No tries for a
solution that was performant enough using lists
and dicts were succesfull, so by inspiration from
the subreddit the final solution code is based on
2 deque() that pops and appends between them.

There are 2 part 1 solutions.

- A correct implementation of the Josephus' Problem,
  using deque(). Recursion would have worked as well,
  but Python do not like recursions.
- The mathematical superior version, with a link
  to the Youtube video were it is introduced.
2024-12-12 13:53:43 +01:00
ae942ce803 Solve 2016:18 p1-2 "Like a Rogue"
Figured out that the center position did not matter,
as long as left hand side tile and right hand side
tile on previous row are not equal.

Also tried to find a recurring pattern to speed
p2 up a bit, but it seems it does not have a
recurring pattern in the 400 000s first rows.
2024-12-12 13:53:43 +01:00
ffc5088813 Improve aoc helper script 2024-12-12 13:53:43 +01:00
3170846595 Solve 2016:17 p1-2 "Two Steps Forward"
Generators baby.
2024-12-12 13:53:43 +01:00
63a7ccd0e2 Simplify scaffold code 2024-12-12 13:53:43 +01:00
cdd5f63be4 Solve 2016:16 p1-2 "Dragon Checksum" 2024-12-12 13:53:43 +01:00
623253ac9d Solve 2016:15 p1-2 "Timing is Everything"
Good TIME to be a Python programmer!
2024-12-12 13:53:43 +01:00
31bb5b7006 Solve 2016:14 p1-2 "One-Time Pad"
Lost 60 minutes due to misinterpreting this in p2:

> *whenever* you generate a hash

The code initially only did the 2016 stretching for
the triplet hash, not the quintet hash. By doing it
to both, pt 2 is solved.

Not sure the lru cache actually speeds anything up.
Many on the subreddit used the approach to generate
the quintet first and look backwards 1000 times
for a matching quintet (since quintets are more
rare than triplets), this will most likely speed
things up.

Also, this solution do not store the found keys.
Many other solutions do, I believe this is some
presumptions.
2024-12-12 13:53:43 +01:00
c113042e17 Solve 2016:11 p1-2 "Radioisotope Thermoelectric Generators"
Hard one, an infamous AoC puzzle according to
Reddit.

Apparently, this is a classic logic problem named
"Missionaries and cannibals", or "Jealous husbands".

Hard lessons:

- Always use set() for visited nodes during BFS.
- Always use collections.queue() to create to queue
  traversals for BFS.
- itertools permutations(), combinations() and
pairwise() may look similar, but they are not.
- Learned to use (?:chunk of text)? in regex.

Test data was achieved without bigger hazzles, but
to optimize code required a lot of Reddit browsing
and code reading from blogs. I have mentioned the
sources in a doc string.
2024-12-12 13:53:43 +01:00
b1b5cda1e3 Solve 2016:12 p1-2 "Leonardo's Monorail" 2024-12-12 13:53:43 +01:00
8d4af7e6e9 Solve 2016:13 p1-2 "A Maze of Twisty Little Cubicles"
BFS baby.
2024-12-12 13:53:43 +01:00