Skip to content

matejker/advent2020

Repository files navigation

Advent of Code 2020

My first attempt with AoC, my only ambition is to solve both problems everyday. Furthermore, I picked up a few nice problems and their solutions and theory.

Day 11 - Game of "Seats"

The theme for day 11 was the Seating System which was a nice adaptation of Cellular Automata or it's most famous variation - the Game of Life. (I am playing with some adaptations with GoL here)

Simulate your seating area by applying the seating rules repeatedly until no seats change state [1]

I rewrite it into JavaScript and visualise it. Here is a live demo for my puzzle: Part 1, Part 2

Day 13 - Chinese Reminder Theorem

Mathematically the most interesting problem was day 13 - Shuttle Search. The solution and idea leads into the Chinese Reminder Theorem. Let m_1,..,m_n be a set of pairwise coprimes, for system of n equation:

x = a_1 (mod m_1)
  .
  .
  .
x = a_n (mod m_n)

then there exist unique solution for x modulo M = m_1...m_n. The solution is

where b_i = M / m_i and b'_i = b_i^-1 (mod m_i) [4, 5].

the earliest timestamp such that the first bus ID departs at that time and each subsequent listed bus ID departs at that subsequent minute. [1]

In the puzzle, all the bus IDs are (surprise-surprise) primes, therefore, we want to have:

x = - a_1 (mod busID_1) <=> x + a_i = 0 (mod busID_1)
  .
  .
  .
x = - a_n (mod busID_n) <=> x + a_i = 0 (mod busID_n)  

Therefore the search by sieving:

multiple = x = buslines[0][1]
for t, bus in buslines[1:]:
    while (x + t) % bus:
        x += multiple
    multiple *= bus

Day 15 - Van Eck's sequence

Rambunctious Recitation or a game with Elves was based on very nice sequence - Van Eck's sequence or Don't Know sequence [3].

For n >= 1, if there exists an m < n such that a(m) = a(n),
take the largest such m and set a(n+1) = n-m; otherwise a(n+1) = 0.
Start with a(1)=0. [2]

Which creates a nice sequence of:

0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5, 0, 2, 6, 5, 4, 0, 5, 3, 0, 3, 2, 9, 0, 4, 9, 3, 6, 14...

One of the nice properties of this sequence is that a(n) < n (or even stronger a(n) + a(n+1) < n [2]), therefore the graph is below the identity x = y. However, the given AoC sequence has given different initial values, I tried to plot it and test it. Obviously, the a(n) > n for a first few n as (in my case) the sequence was defined 1, 2, 16, 19, 18, 0 but asymptotically it should be bellow n. Open questions:

  • What is the slope of the Van Eck's sequence defined by 1, 2, 16, 19, 18, 0? Is it different than the original one?

Day 24 - Axial coordinates

The tiles are all hexagonal; they need to be arranged in a hex grid with a very specific color pattern. [...] tiles are hexagonal, every tile has six neighbors: east, southeast, southwest, west, northwest, and northeast. These directions are given in your list, respectively, as e, se, sw, w, nw, and ne.

This was an interesting one, in the end it ended up as traditional Hexagonal Game of Life, but the interesting part was the notation of tile positions given be list of coordinates. In order to interpret it, I used reddit hint and used Axial coordinates [6] which just worked!

References

[1] Eric Wastl (2020), Advent of Code 2020, https://adventofcode.com/2020
[2] The OEIS Foundation (2010), Van Eck's sequence, https://oeis.org/A181391
[3] Numberphile (2019), Don't Know (the Van Eck Sequence), https://www.youtube.com/watch?v=etMJxB-igrc
[4] Ben Lynn (?), The Chinese Remainder Theorem, https://crypto.stanford.edu/pbc/notes/numbertheory/crt.html [5] Wikipedia (?), The Chinese Remainder Theorem # Search by sieving, https://en.wikipedia.org/wiki/Chinese_remainder_theorem
[6] Amit Patel (2013), Hexagonal Grids, https://www.redblobgames.com/grids/hexagons/#coordinates-axial

About

Advent of Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages