Table of Contents

ceedee666

235757?v=4

ceedee666
: ceedee666

About me

Nothing here yet. Update your profile at /profiles/ceedee666.adoc

Day 01: python

Day 01

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea of this solution is to group the data into a list of lists. Once the data is grouped into a list of lists simple Python functions like sum and max can be used to solve the exercise.

What did I learn

How to use .vimspector.json files to manage debug configurations.

How to run

Run using: $ python day_01.py --help

Day 02: python

Day 02

This solution is written in python.

The following libraries are used to implement the solution
Main idea

The main idea of this solution is to use dicts represent the games.

How to run

Run using: $ python day_02.py --help

Day 03: python

Day ??

This solution is written in python.

The following libraries are used to implement the solution
Main idea

The main idea of this solution is to use sets and set intersection to find the common items

What did I learn

That list comprehension can be use to split list into sub lists.

How to run

Run using: $ python day_03.py --help

Day 04: python

Day ??

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea of this solution is to:

  • check the boundaries of the ranges

  • use the filter function

What did I learn

If you type lamdba istead of lambda it can take quite some time to find the error.

How to run

Run using: $ python day_04.py --help

Day 05: python

Day ??

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea of this solution is to use Python list as stacks. This can be done with the pop() and append() functions.

What did I learn

Parsing text files results in ugly code.

How to run

Run using: $ python day_05.py --help

Day 06: python

Day ??

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea of this solution is to group the input string into substrings of a given length and use a set to check how many different characters are in the substring.

How to run

Run using: $ python day_06.py --help

Day 07: python

Day 07

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea of this solution is to build a tree from the commands. The tree is implemented using dataclasses. The dataclass contains recursive methods to collect all children and to calculate the total size.

What did I learn

I learned a lot about dataclasses, typing and type hints, and enums.

How to run

Run using: $ python day_07.py --help

Day 08: python

Day 08

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

I got a little stuck with the first part today by trying to solve this puzzle using just list comprehension. I worked on rows and cols separately and tried to combine the results by just summing the visible trees in both. However, this does not work as it would count some trees multiple times.

Finally, I changed my approach an iterated through the grid using `range`s.

What did I learn

If you want to use a range to count down the indices of a list be sure to use range(start, -1, -1). Otherwise some of the elements might be missing. === How to run

Run using: $ python day_08.py --help

Day 09: python

Day 09

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea is to use a list of lists to collect the positions of the knots. First the position of the head is updated with each move. Next the positions of all following knots is updated. Positions are simply added to the list. After all moves where executed the list ist converted to a set to get the number visited positions.

What did I learn

One shouldn’t try to be to clever. Instead of trying to use pattern matching to solve this I should have gone for the easier if …​ else…​ approach.

How to run

Run using: $ python day_09.py --help

Day 10: python

Day 10

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

Today was straight forward. Just use a list to keep track of the values of x.

How to run

Run using: $ python day_10.py --help

Day 11: python

Day 11

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

Part one was quite easy. The parsing of the input file was the most complicated part. I used a dict to represent the monkey data. Depending on the operation the mokey performs I added operator.add or operator.mul to the dict. This allowed me to just invoke the correct operation later.

I struggled a litte with the math for part two.

What did I learn

I should work on my basic math skills…​.

How to run

Run using: $ python day_11.py --help

Day 12: python

Day 11

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea is to implement breath first search to find the shortest path from the start to the highest point.

What did I learn

I struggled a little with finding possible neighbours. It took me some time to realize that I need to take the hight into account.

How to run

Run using: $ python day_11.py --help

Day 13: python

Day 13

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea is to implement a comparison function for the lists. This function returns -1, 0 or 1 if the first list is smaller, equal, or larger as the second one. This only became obvious after reading the second part. Luckily a small refactoring of the solution for part one was enough to create the comparison function.

Using the comparison function the second part could be solved by simply using sorted together with the comparison function.

What did I learn

I learned about functools.cmp_to_key today. === How to run

Run using: $ python day_13.py --help

Day 14: python

Day 14

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

The main idea ist to use a dict to represent the cave. (x,y) coordinates are mapped to "R" for rocks and "S" for sand. Using this represenatiton it is easy to check if a certain position (x,y) is already in occupied by either a rock or a sand.

Initially I missed the end condition that a grain of sand could fall into the void, i.e. y in creases beyond the maximum y of any rock.

What did I learn

How to use comprehensions to create `dict`s.

How to run

Run using: $ python day_14.py --help

Day 15: python

Day 15

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

I did really struggle totday. I tried to create all positions and filter those for part one. This wouldn’t work for part two. So I had to change the approach to calculate which ranges of a row are covered by the sensors.

What did I learn

Regex can be really useful to parse files ;)

How to run

Run using: $ python day_15.py --help

Day 16: python

Day 15

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

I did really struggle totday. I tried to create all positions and filter those for part one. This wouldn’t work for part two. So I had to change the approach to calculate which ranges of a row are covered by the sensors.

What did I learn

Regex can be really useful to parse files ;)

How to run

Run using: $ python day_15.py --help

Day 17: python

Day 15

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

I did really struggle today. I tried to create all positions and filter those for part one. This wouldn’t work for part two. So I had to change the approach to calculate which ranges of a row are covered by the sensors.

What did I learn

Regex can be really useful to parse files ;)

How to run

Run using: $ python day_15.py --help

Day 18: python

Day 18

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

First I just counted cubes. For the second part I had to change my approach. I implemented a flooding algorithm to find the outside. After that I calculated all neighbours of the cubes and counted only the ones visible from the outside.

What did I learn

I extended my knowledge of list comprehension. Such a cool feature!

How to run

Run using: $ python day_18.py --help

Day 19: python

Day 19

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

I didn’t really have an idea for today. Brute force seemed to be to slow. With some inspiration from reddit I was able to finally solve today.

How to run

Run using: $ python day_19.py --help

Day 20: python

Day 20

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

Solved today using deque from the collections module. This was my first idea. However, I then tried using indices and modulo arithmetic instead. Couldn’t get a nice solution and finally got back to the deque approach.

How to run

Run using: $ python day_20.py --help

Day 21: python

Day 21

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

Implemented something similar to a binary search. The main idea was to increase the steps in each iteration and change directions when the sign of the difference between the result and the expected value changes.

How to run

Run using: $ python day_21.py --help

Day 22: python

Day 22

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

Only solved part one today.

What did I learn

When zipping two lists make sure they are of equal lenght.

How to run

Run using: $ python day_22.py --help

Day 23: python

Day 22

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

Only solved part one today.

What did I learn

When zipping two lists make sure they are of equal lenght.

How to run

Run using: $ python day_22.py --help

Day 24: python

Day 24

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

Basically use sets to keep track of the state. I very useful ideas is to move all positions -1 in x and y direction. This enables much simpler calculations. The next positions of the blizzards can then, e.g. simply be calculated using a modulo operation.

What did I learn

It is not necessary to create a list wen using max. The following is possible as well. This approach creates a generator. Have to read some more details on generators I guess.

max_x = max(x for x, _ in walls)
How to run

Run using: $ python day_24.py --help

Day 25: python

Day 24

This solution is written in python.

The following libraries are used to implement the solution:

Main idea

Basically use sets to keep track of the state. I very useful ideas is to move all positions -1 in x and y direction. This enables much simpler calculations. The next positions of the blizzards can then, e.g. simply be calculated using a modulo operation.

What did I learn

It is not necessary to create a list wen using max. The following is possible as well. This approach creates a generator. Have to read some more details on generators I guess.

max_x = max(x for x, _ in walls)
How to run

Run using: $ python day_24.py --help