Skip to content

monpie3/adventOfCode2024

Repository files navigation

adventOfCode2024 🎄

Python application codecov

You can find the puzzle inputs here: https://adventofcode.com/2024

Recap of my progress in Advent of Code so far:

  • 2023: 22 days (36 ⭐)
  • 2020: 10 days (19 ⭐)

What have I learned this year?

Day 1

  • How to use Git credential store on WSL → 🔗
  • How to change the default editor from nano to vim → 🔗

Day 2

meme from day 2

Day 3

  • A good reminder that . by default matches any character except a new line. So, I learned about DOTALL flag.
  • I came across this website: https://regexcrossword.com/

meme from day 3

Day 4

meme from day 4

Day 5

  • The better solution is to use sorting with a custom comparator function →

better solution for day 5

Day 6

  • Used time python Day_06/task_6b.py to measure the execution time of the script

meme from day 6

secend meme from day 6

Day 7

  • The go-to solution: itertools.product

meme from day 7

Day 8

  • Using the next iterator from itertoolscombinations

  • A cleaner way to handle this kind of logic. Instead of writing:

if cell not in antenna_positions:
    antenna_positions[cell] = [(row_ind, col_ind)]
else:
    antenna_positions[cell].append((row_ind, col_ind))

We can refactor it to be more concise: antenna_positions.setdefault(cell, []).append((row_ind, col_ind))

Alternatively, we can use defaultdict from collections, which automatically provides a default value for the key that doesn't exist.

Day 09

In part two, I got rid of OrderedDict since I hadn't actually used it in part one anyway. To improve performance, I changed the structure from index: file_id to file_id: [list of indices], as searching through the old dictionary was painfully slow. I also replaced the while loop with a for loop (always a pleasure) 😇

Day 10

meme from day 10

Been there, done that 😅

Day 11

The choice of a dynamic list as a data container was not the best. It turns out that order was not important at all, and it would have been much better to use a hash map where the key would be the engraved number and the value the number of occurrences.

nicer solution for day 11

I also read that returning from a with block (e.g., when opening a file) works fine, and the file is automatically closed. The with statement ensures cleanup happens, whether the block exits normally or via a return. 🔗

Day 12

I probably would have done better if my puzzle_input had been correct instead of last year's 😅 But this was one of those tasks I really liked (aside from the wrong input), where I had to grab a sheet of paper and a pen to plan it out. What I’m proud of is that I came up with the correct perimeter formula right away. Even though it’s a bit basic, it works!

amazing trolling from JS

Day 17

The match statement is a more elegant alternative to if...elif...else

Day 18

meme from day 18

Brute force was good enough, so I stuck with it. Apparently, you can practically reuse part 2 from day 16 (you just need to remove the condition about 1000 points → 🔗), but I don’t have that part ready yet, so we’ll see in the future 😅

Day 20

Part 1: I forgot that two picoseconds are needed for the cheating, so the distance isn’t simply the difference between the end position index and the start position index—we need to reduce it by 2.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages