Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
/ advent_of_code_2020 Public archive

Python notebook with solutions and timings for the 2020 Advent of Code

License

Notifications You must be signed in to change notification settings

hhoppe/advent_of_code_2020

Repository files navigation

Advent of code 2020

[Open the notebook in Colab]

IPython/Jupyter notebook by Hugues Hoppe; December 2020.

I participated in the 25-day Advent of Code for the first time this year, thanks to encouragement from colleagues, especially Sascha Häberling. It was great fun and provided a nice opportunity to learn more advanced Python.

In the event, many people compete to solve the puzzles as quickly as possible --- see the impressive times on the leaderboard. My approach was much more casual, although I did aim to finish the puzzle each evening.

Later, I went back to explore more polished and efficient solutions. Can the code be expressed more succinctly? What is the fastest algorithm given the constraints of interpreted Python? Along the way, I discovered the numba package which can JIT-compile bottleneck functions to native code; is it practical for these problems? Yes, it can help greatly!

This notebook is organized such that each day is self-contained and can be run on its own after the preamble.

Some conclusions:

  • A Jupyter/IPython notebook is a great environment for exploration.
  • The notebook conveniently bundles descriptions, notes, code, small test inputs, and results.
  • Initially I stored puzzle inputs within the notebook itself, but this introduces clutter and runs inefficiently.
  • The cloud-based CPU kernel/runtime provided by Colab works nicely.
  • With the numba library (for days 11, 15, and 23), all of this year's puzzles can be solved in 1 second or less.
  • The total execution time across all 25 puzzles is about 4 s.

Here are some visualization results:

day11 day20
day24

About

Python notebook with solutions and timings for the 2020 Advent of Code

Topics

Resources

License

Stars

Watchers

Forks