Commit graph

16 commits

Author SHA1 Message Date
89299cefa1 Solve 2021:13 "Transparent Origami"
finally sub 60 minutes again.
2021-12-13 07:09:56 +01:00
c0d352cdf1 Solve 2021:12 "Passage Pathing"
I struggled a lot with the direction, but realised way too much later
that the mappings are bidirectional.

Part 2 was exceptionally hard, but I realised early that the order did
not matter and that a simple boolean lock was all that was needed. The
challenge was to know when to watch for duplicates.

The seen was initially a set, but since new sets must be sent instead of
references, a list is used instead to be able to use the seen + [] hack.
2021-12-12 14:39:11 +01:00
b53c50addc Solve 2021:11 "Dumbo Octopus" 2021-12-11 09:36:09 +01:00
801f977e92 Solve 2021:10 "Syntax Scoring"
Spent over an hour trying to figure out the incomplete sequenses, only
to realize it was easier to begin from the other way around.

After that, solution came out nice and clean.
2021-12-10 13:27:55 +01:00
95c244102f Solve 2021:9 "Smoke Basin" part 2
Yet again I got stuck in the common AOC trap: The example input worked,
but not the actual input.

2 things got me stuck.

> The size of a basin is the number of locations within the basin, including the low point. The example above has four basins.

1. I missed the obvious part to only check the low points.

2. Based on the example, I asumed that the adjacent locations would
   increase by one to count. This is wrong: What matters is that their
   height is a larger value.

Way too long time for a simple problem. Never read puzzles sloppy.
2021-12-09 11:00:28 +01:00
c7753f58fc Solve 2021:9 "Smoke Basin"
Had to rewrite whole solution due to getting the example input right,
but wrong on the actual puzzle input. Off by like 20.
2021-12-09 07:39:53 +01:00
811d2cb224 Solve 2021:8 "Seven Segment Search"
For part 1, it took way longer than necessary since I read the
instructions over and over again. Gotta love AOC WOT.

Part 2 was a PITA. I got stuck at the last 2 examples since I at the
time did not find any clever way to determine which of the 2 outputs for
'1' mapped to c and f.

Since I already spent far too much time and effort, a try/except with
ValueError (digits.index will fail if c and f are flipped wrong) will do
for now.

There is probably a more efficient and smart way to do this.
2021-12-08 11:35:18 +01:00
69c4518f29 Solve 2021:7 "The Treachery of Whales" 2021-12-07 09:47:54 +01:00
bfe94864e9 Solve 2021:6 "Lanternfish" part 2
Part 2 requires more clever code. In the first part, I kept track on
every single fish on order, much like the output of the example in the
puzzle.

However, by increasing the day count to 256, my code became obese and
would not run to the end: the OS killed it before it was done. It halted
around 150 days.

Browsing the sub reddit, I quickly realised that the current state of
each fish individually did not matter. For example:

    3,4,3,1,2

This says 2 fishes has a timer set to 3, and 1 fish each has a timer of
1, 2 and 4.

Add one day, and we have

    2,3,2,0,1

This says 2 fishes has a timer set to 2, and 1 fish each has a timer of
0, 1 and 3.

Notice how **the relative count does not change** (2, 1, 1, 1).

By using the excellent collections.counter, you get

    >>> from collections import Counter
    >>> Counter([3,4,3,1,2])
    Counter({3: 2, 4: 1, 1: 1, 2: 1})
    >>> Counter([2,3,2,0,1])
    Counter({2: 2, 3: 1, 0: 1, 1: 1})
    >>>

If visualized in a tabulat view, you get this:

                   0  1  2  3  4  5  6
    ----------------------------------
    Initial           1  1  2  1
    Day 1          1  1  2  1

The sequence moves **one step to the left each day**. Add another day,
and something extra happens.

                   0  1  2  3  4  5  6  7  8
    ----------------------------------------
    Initial           1  1  2  1
    Day 1          1  1  2  1
    Day 2          1  2  1           1     1

2 things:

 * A value higher than zero pops out on the left. By rules, 1 fish
   has created 1 new fish, and resets its timer to 6.
 * The new fish created has a timer of 8, since it will need 2 days
   before it is able to start the create timer.

There are now 6 fishes.

Now, what happens on day 3?

                   0  1  2  3  4  5  6  7  8
    ----------------------------------------
    Initial           1  1  2  1
    Day 1          1  1  2  1
    Day 2          1  2  1           1     1
    Day 3          2  1           1  1  1  1

Now this happened:

 * The fish on 0 creates a new fish, resets to 6.
 * The created fish, once again, has a timer of 8.
 * The fish created on day 2 decreases timer to 7.

There are now 7 fishes.

And so it continues. In Python, the most memory efficient and performant
method of leftpadding a list of values is to use collections.deque, with
the functions popleft and append.
2021-12-06 07:49:46 +01:00
2f3f892c0e Solve 2021:6 "Lanternfish" part 1 2021-12-06 07:15:37 +01:00
f82b6cd9b5 Solve 2021:5 "Hydrothermal Venture"
Tricky part, got the test data correct at part 1 long before the actual input gace the correct answers. Pure luck I guess.

Part 2 I got stuck on, and resolved to visualization by a loop of
prints.
2021-12-05 08:30:54 +01:00
661440e4ce Solve 2021:4 "Giant squid" 2021-12-04 07:12:00 +01:00
99f5385f25 Solve 2021:3 "Binary Diagnostic"
Yes, I do "".join(). Python is not always beautiful.

I began reusing part 1 for part 2, until I realised you cannot reuse the
Counter.most_common, and you need the actual values to be able to se
equal occourences.

I probably lost 5-15 minutes just to dribble with 3 levels of nested
objects. In GMT+1 before coffee, that cost me.

Part 2 was way uglier before some well motivated refactoring. Since all
tests and expected output were in place, refactoring was easy.
2021-12-03 07:29:34 +01:00
d63c7463cc Solve 2021:2 "Drive!" 2021-12-02 06:42:42 +01:00
9976edc457 Solve 2021:1 "Sonar sweep"
Felt a bit slow and rusty. Tooling was not set up properly on the
computer which decreased the flow.

Anyhow, fun first day! Could have been done more pythonic with list sequences, and readability would have increased with more use of sum() and lambdas. But this is not what Advent of Code is about.
2021-12-01 06:38:45 +01:00
Anders Ytterström
d5a29d41e2 🔧 Setup Advent of Code 2021
This year: Elixir! And maybe python.
2021-10-22 17:17:55 +02:00