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.

Ler mais

Advent of code 2024 - Dia 05 de 25

O quinto dia do Advent of Code foi ontem 05/12/2024! Se você caiu aqui hoje pela primeira vez, não deixe de ler os posts sobre o Dia 1, Dia 2, Dia 3, e Dia 4!

Classifiquei o quinto problema como fácil (parte 1) e médio (parte 2).

Dicas

  • O problema tem duas entradas, uma lista de regras e uma lista de atualizações.

  • As páginas presentes na lista de regras (X) devem ser impressas antes das páginas (Y). Como a mesma página X pode ter várias Y, as regras são um dicionário com chaves do tipo int e listas também do tipo int.

Ler mais

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.

Ler mais

Advent of code 2024 - Dia 04 de 25

O quarto dia do Advent of Code foi ontem 04/12/2024! Se você caiu aqui hoje pela primeira vez, não deixe de ler os posts sobre o Dia 1, Dia 2 e Dia 3!

Classifiquei o quarto problema como médio (parte 1) e difícil (parte 2).

Dicas

  • Se você visualizar as entradas como uma matriz, a solução fica mais natural.

  • Considere que cada caractere ocupa uma posição y, x na matriz, onde y é a linha e x a coluna.

Ler mais

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.

Ler mais

Advent of code 2024 - Dia 03 de 25

O terceiro dia do Advent of Code foi ontem 03/12/2024! Se você caiu aqui hoje pela primeira vez, não deixe de ler os posts sobre o Dia 1 e o Dia 2!

Classifiquei o terceiro problema como fácil (parte 1) e médio (parte 2).

Dicas

  • Você pode utilizar expressões regulares para detectar mul e extrair os números.
  • Na segunda parte, você pode utilizar uma máquina de estados simples para ativar ou desativar as multiplicações.
  • Lembre-se de re.compile e re.findall.

Quanto de Python você precisa saber?

Os capítulos se referem ao meu livro Introdução à Programação com Python.

Ler mais

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:

Ler mais

Advent of code 2024 - Dia 02 de 25

Segundo dia do Advent of Code foi ontem 02/12/2024! Se você caiu aqui hoje pela primeira vez, não deixe de ler o post sobre o Dia 1!

Classifiquei o segundo problema como fácil (parte 1) e médio (parte 2).

Dicas

  • Você precisa transformar cada linha de entrada em uma lista de inteiros.
  • Para saber se a lista é crescente ou decrescente, calcule a diferença entre o segundo e o primeiro elemento. O sinal do resultado da subtração indicará se a lista é deve ser crescente ou decrescente. Para saber se a lista inteira é crescente ou decrescente, continue subtraindo os elementos, dois a dois, até o final da lista. Quando a valor da subtração for positivo, a lista é crescente. Se negativo, a lista é decrescente. Mas somente se o mesmo sinal for mantido até o final da lista.
  • Lembre-se que como usamos L[i+1] - L[i], i deve ser menor que o índice do último elemento, caso contrário você terá um erro.

Exemplo de lista crescente:

Ler mais

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.

Ler mais

Advent of code 2024 - Dia 01 de 25

O Advent of Code é um desafio de programação que acontece entre os dias 1 e 25 de dezembro de cada ano. O de 2024, é a décima edição do evento que é independente de linguagem de programação, você pode usar as ferramentas que você quiser.

Todo dia, a partir do dia primeiro de dezembro, um novo problema é disponibilizado. Embora o nome seja Advent of Code (Advento é um evento cristão que antecede o Natal), os problemas não envolvem necessariamente religião, mas são problemas divertidos com os duendes de Papai Noel.

Ler mais