This repo covers some Julia answers to the Advent of Code 2022 problems. A brief summary of each of the statements of each problem is shown below.
- Calorie Counting
- Rock Paper Scissors
- Rucksack Reorganization
- Camp Cleanup
- Supply Stacks
- Tuning Trouble
- No Space Left On Device
- Treetop Tree House
- Rope Bridge
- Cathode-Ray Tube
- Monkey in the Middle
- Hill Climbing Algorithm
The input is a list of numbers (calories) separated by empty lines (that marks the separation between each elf). The goals of the problem are:
- Part 1: Calculate the maximum value of the sum of blocks in the file.
- Part 2: Calculate the sum of the 3 largest sums of blocks in the file.
The input is a two column list of letters. The first column represent the opponent elf's choice for the game rock (A), paper (B) and scissors (C). The second column represents:
- Part 1: The player's choice for the game rock (X), paper (Y) and scissors (Z).
- Part 2: The result of the game, i.e. if it is a lose (X), tie (Y) or win (Z).
Thus, choosing rock, paper or scissors gives 1, 2 and 3 points, respectively, and loosing, drawing or winning gives 0, 3 and 6 points. The aim is to see what score would be obtained in each case.
The input is a list of characters in a singles line, corresponding each line to one rucksack. Each character on that list has a priority number a assigned being 1-26 to a-z and 27-52 to A-Z.
- Part 1: Calculate the sum of the priorities of the elements that are repeated in each half of the different rucksacks.
- Part 2: Calculate the sum of the priorities of the elements that are repeated in the groups of three rucksacks.
The input is a list of numbers in the format: a-b,x-y, which represent two ranges a:b and x:y.
- Part 1: Calculate how many pairs of ranges are fully contained in their associate range.
- Part 2: Calculate how many pairs of ranges have at least one element in common.
The input is a list of stacks of characters (crates) and a set of instructions to move this characters.
- Part 1: The top crates of each list if the moves are applied to the elements one by one.
- Part 2: The top crates of each list if the moves are applied to whole blocks (keeping the order).
The input is a string of characters.
- Part 1: Find the index for the first block of 4 different characters (the index of the last number of the block).
- Part 2: Find the index for the first block of 14 different characters (the index of the last number of the block).
The input is a log of commands with information about a filesystem. A more elaborate program by using structs can be created, but in this case I prefer to keep it simple (although some folder structure information, that is not relevant to the problem, is lost).
- Part 1: Find the sum of the sizes of directories with sizes less than 100000.
- Part 2: Find the shortest directory to free up the needed space.
The input is a matrix of trees' heights.
- Part 1: Find the number of trees that are visible (a tree is visible if all of the other trees between it and an edge of the grid are shorter than it).
- Part 2: Find the highest scenic score. The scenic score is found by multiplying together its viewing distance in each of the four directions, where the viewing distance is defined as the number of trees between a given tree and an edge that are visible from said tree.
The input is a list of instructions for the 2D movement of the head of a rope, where the letter represents a direction (up, down, left, right) and the number is the steps in said direction.
- Part 1: For a rope with 2 knots, find the number of unique positions visited by the tail of the rope (knot 2).
- Part 2: For a rope with 10 knots, find the number of unique positions visited by the tail of the rope (knot 10).
The input is a list of instructions for controlling an image display.
- Part 1: Add the product of a signal value and the cycle for a given number of equispaced cycles.
- Part 2: Create an image taking into account that a certain pixel of the display lights up if the cycle match with the CRT.
The input is a list of monkeys written as described here.
- Part 1: After 20 games, obtain the product of the inspected items of the two most active monkeys. In this case, the monkeys get bored with items and divide its worry level by 3.
- Part 2: After 10000 games, obtain the product of the inspected items of the two most active monkeys. In this case, the monkeys don't get bored with items and the worry level must be scaled to avoid overflow errors.
The input is a height map (each heigth is mapped with a lowercase letter) with a marked start point (S) and end point (E), with minimum (a) and maximum (z) heigth respectively. To solve the exercise, an Dijkstra's algorithm will be used.
- Part 1: Find the length of the shortest path from the starting to the end point.
- Part 2: Find the length of the shortest path from any 'a' point to the end point.