Posts for: #Adventofcode

Advent of Code 2024 - Day 05 of 25

The fifth day of Advent of Code was yesterday 12/05/2024! If you’re here for the first time today, don’t forget to read the posts about Day 1, Day 2, Day 3, and Day 4!

I classified the fifth problem as easy (part 1) and medium (part 2).

Tips

  • The problem has two inputs, a list of rules and a list of updates.

  • The pages present in the rules list (X) must be printed before pages (Y). Since the same page X can have multiple Y’s, the rules are a dictionary with integer keys and lists of integers as values.

Read more

Advent of Code 2024 - Day 04 of 25

The fourth day of Advent of Code was yesterday 12/04/2024! If you’re here for the first time today, don’t forget to read the posts about Day 1, Day 2 and Day 3!

I classified the fourth problem as medium (part 1) and hard (part 2).

Tips

  • If you visualize the inputs as a matrix, the solution becomes more natural.

  • Consider that each character occupies a position y, x in the matrix, where y is the row and x is the column.

Read more

Advent of Code 2024 - Day 03 of 25

The third day of Advent of Code was yesterday 12/03/2024! If you’re here for the first time today, don’t forget to read the post about Day 1 and Day 2!

I classified the third problem as easy (part 1) and medium (part 2).

Tips

  • You can use regular expressions to detect mul and extract numbers.
  • In the second part, you can use a simple state machine to enable or disable multiplications.
  • Remember re.compile and re.findall.

How much Python do you need to know?

The chapters refer to my book Introduction to Programming with Python.

Read more

Advent of Code 2024 - Day 02 of 25

Second day of Advent of Code was yesterday 12/02/2024! If you’re here for the first time today, don’t forget to read the post about Day 1!

I classified the second problem as easy (part 1) and medium (part 2).

Tips

  • You need to transform each input line into a list of integers.
  • To determine if the list is increasing or decreasing, calculate the difference between the second and first element. The sign of the subtraction result will indicate if the list should be increasing or decreasing. To check if the entire list is increasing or decreasing, continue subtracting elements, two at a time, until the end of the list. When the subtraction value is positive, the list is increasing. If negative, the list is decreasing. But only if the same sign is maintained until the end of the list.
  • Remember that since we use L[i+1] - L[i], i must be less than the index of the last element, otherwise you’ll get an error.

Example of an increasing list:

Read more

Advent of Code 2024 - Day 01 of 25

The Advent of Code is a programming challenge that takes place between December 1st and 25th each year. The 2024 edition is the tenth event that is programming language independent - you can use any tools you want.

Every day, starting from December first, a new problem is released. Although the name is Advent of Code (Advent is a Christian event that precedes Christmas), the problems don’t necessarily involve religion, but are fun problems with Santa’s elves.

Read more