Coder Social home page Coder Social logo

mjpieters / adventofcode Goto Github PK

View Code? Open in Web Editor NEW
146.0 5.0 15.0 64.88 MB

Advent of Code solutions 2015-2023

License: MIT License

Jupyter Notebook 99.67% Python 0.26% Shell 0.01% Rust 0.08%
advent-of-code advent-of-code-2015 advent-of-code-2016 advent-of-code-2017 advent-of-code-2018 advent-of-code-2019 aoc aoc2015 aoc2016 aoc2017

adventofcode's Introduction

Advent of code solutions

Author: Martijn Pieters
Twitter: @zopatista
GitHub: mjpieters

These are my Advent of Code (AoC) puzzle solutions.

Most recent solutions use Python 3.12, and are presented in Jupyter notebooks for easy viewing on GitHub or the online Jupyter notebook viewer. The latter is the better viewer, especially as Github's notebook rendered often breaks or at the very least filters out a lot of the interesting bits like animations.

I don't aim to be first on any leaderboard. I aim to have fun solving the coding puzzles and playing with the concepts, and I try to include explanations of my thinking in the notebooks. Sometimes that means I'll include an animation or graph to show off some aspect of the puzzle.

Running locally

Everything here is run through Jupyter notebooks. If you check out this repository locally everything is included to recreate my environment.

I use Pipenv to manage dependencies, make sure you have it installed before continuing. Once installed, run

$ pipenv install
$ ./start

and the jupyter notebook interface is automatically opened in your default browser. You can stop the server with the Quit button in the web interface, or with the ./stop script.

Everything is organised in per-year folders. I tend to update all the libraries and Python release each year, but I don't test if these updates caused issues with solutions for preceding years. If something broke, so be it.

Additional dependencies

  • Animations are produced using matplotlib's animation API, which requires ffmpeg to be installed. On Mac OS X just use brew install ffmpeg.

  • Graphs are plotted using graphviz command-line tools such as dot, neato, and tred. On Mac OS X, just use brew install graphviz.

Puzzle input data

I use Wim Glenn's advent-of-code-data package to load data directly from the AoC website. This library requires your AoC session cookie. You'll have create your own Advent of Code account, then use your browser development tools to retrieve the session cookie value. Store the value according to the advent-of-code-data instructions (either in ~/.config/aocd/token or in the AOC_SESSION environment variable).

Since this project uses poetry, I use poetry-dotenv-plugin and I store the session cookie in a .env file in the root directory of this project:

AOC_SESSION=deadbeafdeadbeafdeadbeafdeadbeafdeadbeafdeadbeafdeadbeafdeadbeaf

Do make sure to restart the jupyter notebook server after updating this file.

2015 and 2016 solutions

The 2015 and 2016 solutions are not IPython notebooks; they pre-date this repository, but were added later, and have not been updated or tested to work still. These don't use the advent-of-code-data library either so you need to download inputs manually for these.

They are included purely for completion's sake.

Rust solutions

I'm trying out implementing solutions in Rust as well. I can't promise I'm going to keep this up or that I'll implement Rust versions of all solutions.

I'm using the cargo-aoc project as the runner; you'll need to run cargo install cargo-aoc to install it. Then, set your AoC credentials (cargo aoc credentials -p ...), move your working directory to a specific year (cd rust/<year>, fetch inputs cargo aoc input -y <year> -d <day> and you can run the solution for that day with cargo aoc -d <day>.

Like with my Python solutions, I did not include my own puzzle inputs in the repository.

License

See the LICENSE file in the same directory.


adventofcode's People

Contributors

dependabot[bot] avatar mjpieters avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

adventofcode's Issues

2020 day 1 bug

This algorithm made assumption that half the target is not in the set. Example, with input coins:

1010
786
1234

It's needed to find the 786*1234 solution and not 1010*1010. Probably better to use a multiset (collections.Counter).

example missing in 2022/19

Nice notebooks this year, Martijn! I noticed the assert in Day 19.ipynb part 2 is bogus:

assert reduce(mul, largest_number_geodes(example))

It should be

assert reduce(mul, largest_number_geodes(example)) == 3472

Or even better

assert math.prod(largest_number_geodes(example)) == 3472

Thank you!

Hey there!
Not really an issue, just wanted to thank you for explaining day 6 so well in your solution.
I was quite stuck and really helped me solve it. Thanks again and happy holidays!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.