# Advent of Code 2018, Days 1-5 in Python

## »Day 1: Chronal Calibration«

In the first day’s task, we are given a list of frequency changes.

# Preprocessing

# Part 1

The first part asks us to do nothing else than to sum up the frequency changes.

# Part 2

The slightly more complicated second part asks us to find the first frequency that appears twice, when cummulatively summing over the list of frequency changes.

## »Day 2: Inventory Management System«

The second day’s task presents us with a list of box IDs.

# Preprocessing

# Part 1

We are to calculate the checksum of the inventory, for which we need to multiply two quantities. The first one is the number of IDs in which some letter appears exactly twice, the second one the number of IDs in which some letter appears exactly thrice.

# Part 2

In the second part, another piece of information is revealed to us: among the pairs of IDs, there is exactly one pair which differs exactly in one letter. We simply define a distance function between two IDs to be the number of letters in which they differ, and iterate over all pairs.

## »Day 3: No Matter How You Slice It«

In the third day, we are given a list of (possibly overlaping) rectangles in a grid.

# Preprocessing

# Part 1

The first part asks us to count the number of squares in the grid that are part of at least two rectangles.

# Part 2

We are informed that precisely one of the rectangles does not overlap with any other rectangle. The problem asks us to find its ID. For this, we make use of the previously created Counter object.

## »Day 4: Repose Record«

In the fourth day, we are given a number of records about the sleeping habits of guards. In the preprocessing step, we shall parse from the input the intervals of naps for each of the guards.

# Preprocessing

# Part 1

There are two quantities that we need to find: the guard that has cummulatively slept for the most time, and the minute that this guard spend asleep the most.

# Part 2

For the part 2, we need to find the following quantity: among all pairs (guard, minute) we need to find the one where the given guide has spend the given minute asleep the most.

## »Day 5: Alchemical Reduction«

In the problem of day 5, we are given a string consisting of lowercase and uppercase alphabet characters. When two letters of opposite lower/upper case meet in the word, they annihilate themselves.

# Preprocessing

In the first part, we are bound to find the length of the string after all annihilations have taken place. For this, a single pass over a stack will be sufficient.

# Part 1

In the second part, we are permitted to remove one letter (both lowercase and uppercase) from the string. Our goal is to find out what the minimum possible length of a string is after such a removal and after all annihilations take place. Brute force is sufficient here.