Commit graph

7 commits

Author SHA1 Message Date
7b2b101b8b Solve 2024:6 p1-2 "Guard Gallivant"
Pt 1 was easy, Pt 2 was pure horror.

Earlier drafts of the code tried to be way too
smart. At one point, I just came to the conclusion
to place a new obstacle (#) on the grid and just
rerun the thing to look for loops.

2 things:

- the visited positions from pt 1 can be used as a
subset for positions to consider for the extra
"#".
- The track of loops can be optimized to look at
bounces on "#"s instead of each individual y,x pos,
given that the direction is remembered.

pt 2 is familiar, the last time a puzzle required
look detection the puzzle used lazer beams and
reflectors. Not sure what Event or day it was.
2025-01-05 00:06:18 +01:00
44f6aa0f53 Solve 2024:5 p1-2 "Print Queue"
In p2, it took some tries to find a correct way
to rearrange incorrect pagesets. The code ended
up just rearranging first found incorrect order
and readding the updated pageset to queue.
2025-01-05 00:06:18 +01:00
f751b3b8d5 Solve 2024:4 p1-2 "Ceres Search"
Not gonna lie, This is not my gig skillwise. I had
much fun though!

A matrix would most likely make the code more
readable.

I relied massively on test cases here, so I share
them here instead of in the source code:

assert 1 == solve("""
    X.....
    .M....
    ..A...
    ...S..
    ..X...
    """.strip())[0]

    assert 2 == solve("""
    XS....
    .MA...
    ..AM..
    ...SX.
    ..X...
    """.strip())[0]

    assert 2 == solve("""
    ..S......
    ...A.....
    ....M....
    .....X...
    ..X...M..
    .......A.
    ........S
    """.strip())[0]

    assert 4 == solve("""
    X.SS
    M.AA
    A.MM
    S.XX
    ...M
    ...A
    ...S
    """.strip())[0]

    assert 4 == solve("""
    ...X...
    ...M...
    .X.A...
    XMASAMX
    .A.....
    .S.....
    """.strip())[0]

    assert 1 == solve("""
    ....X
    ...M.
    ..A..
    .S...
    """.strip())[0]

    assert 2 == solve("""
    ...SX
    ..AM.
    .MA..
    XS...
    """.strip())[0]

    assert 2 == solve("""
    ......X
    .....M.
    ....A..
    ...S...
    ..A....
    .M.....
    X......
    """.strip())[0]

    assert 1 == solve("""
    M.S
    .A.
    M.S
    """.strip())[1]

    assert 1 == solve("""
    M.M
    .A.
    S.S
    """.strip())[1]

    assert 1 == solve("""
    S.M
    .A.
    S.M
    """.strip())[1]

    assert 1 == solve("""
    S.S
    .A.
    M.M
    """.strip())[1]

    assert 1 == solve("""
    S.S
    .A.
    M.M
    """.strip())[1]

    assert 1 == solve("""
    .A.
    M.M
    .A.
    S.S
    """.strip())[1]

    assert 1 == solve("""
    M.M.
    .A.A
    S.S.
    """.strip())[1]

    assert 1 == solve("""
    M.M
    .A.
    S.S
    .A.
    """.strip())[1]

    assert 1 == solve("""
    .M.M
    A.A.
    .S.S
    """.strip())[1]
2025-01-05 00:06:18 +01:00
cb622409f9 Solve 2024:3 p1-2 "Mull It Over"
Felt paranoid on this one, was expecting something
much worse for pt2.

The code that solved the puzzle was _extremely_
naive:

- It asumes puzzle input only contains mul() with
1-3 chars. The versioned code have `{1,3}` as safe
guard.
- p2 asumed initial chunk does not begin with
"n't". Would have been easy to handle though.
- p2 asumed junk strings as "don", "do", "don()t"
would not exist.

In other words, I was really lucky since I did not
look that closely on puzzle input beforehand.

Might have cut 60-90 seconds further if I had just
ran pt2 immidately instead of staring dumbly on the
test data (that changed for pt2).

Also, I got reminded that \d in regular expressions
is equal to `0-9`: it does not include commas and
punctations. The code that solved the puzzle was
paranoid and instead used `0-9`.

Managed to score ~1500th somehow despite this.
2025-01-05 00:06:18 +01:00
5deb351504 Solve 2024:2 p1-2 "Red-Nosed Reports"
DDOS of adventofcode.com, did not get to open the
puzzle until 06:05 (five minutes local time).

Screwed up the zip() and lost valuable minutes by
trying to replace it with itertools, only to find
I have made a typo (did AB CD EF instead of AB BC
CD).

I also lost valuable minutes by tring to solve p1
with one nested loop. Stupid.

For part 2, I created the issafe() helper to be
able to remove items from reports and test, one
at the time.
2025-01-05 00:06:18 +01:00
81741232af Solve 2024:1 p1-2 "Historian Hysteria"
Realized afterwards I got the ints() helper, so
original code before cleanup splitted the input and
mapped all words with int(). valuable seconds lost
there.

Also, collections.Counter() was used initially since
I was too tired to remember count() method in lists.

Line 8 took the longest time to figure out. A typo
took 1-3 minutes to find for part 2.

Form: Sleep deprived, felt slow.
2025-01-05 00:06:18 +01:00
cb50d62e3f Prepare for AOC 2024
Python, again.

10th year anniverary.
2025-01-05 00:06:18 +01:00