106 stable releases

new 2019.12.155 Nov 26, 2020
2019.12.150 Nov 16, 2020
2019.12.126 Oct 29, 2020
2019.12.80 Sep 30, 2020

#64 in Rust patterns

Download history 18/week @ 2020-09-04 221/week @ 2020-09-11 156/week @ 2020-09-18 150/week @ 2020-09-25 135/week @ 2020-10-02 216/week @ 2020-10-09 457/week @ 2020-10-16 202/week @ 2020-10-23 392/week @ 2020-10-30 242/week @ 2020-11-06 114/week @ 2020-11-13 50/week @ 2020-11-20

784 downloads per month

MIT license

365KB
9K SLoC

Crates.io Docker Hub npm PyPi

Build Netlify Status

Advent of Code solutions

Solutions to Advent of Code problems in Rust.

Libraries

The solve(year, day, part, input) library function is published to these package repositories:

// Rust with dependency added: advent-of-code = "2019"
use advent_of_code::solve;

fn main() {
    assert_eq!(solve(2019, 1, 1, "14"), Ok("2".to_string()));
}
# Python with dependency added: pip install --upgrade advent-of-code
from advent_of_code import solve

assert solve(2019, 1, 1, "14") == "2"
assert solve(2019, 3, 2, "R8,U5,L5,D3\nU7,R6,D4,L4") == "30"
// Node.js with dependency added: npm add advent-of-code-wasm
const assert = require('assert').strict;
const solve = require('advent-of-code-wasm').solve;

assert.equal(solve(2019, 1, 1, "14"), "2");
assert.equal(solve(2019, 3, 2, "R8,U5,L5,D3\nU7,R6,D4,L4"), "30");

Running in the browser

The solutions can be run client-side in a browser using WebAssembly at https://aoc.fornwall.net.

Post to HTTP endpoint

There is an HTTP endpoint running on Netlify Functions (using Node.js and WebAssembly) that can be used as follows:

$ curl -d 14 "https://aoc.fornwall.net/solve/2019/1/1"
14
$ curl -s https://raw.githubusercontent.com/fornwall/advent-of-code/master/crates/core/src/year2019/day02_input.txt | \
  curl --data-binary @- \
     "https://aoc.fornwall.net/solve/2019/2/2"
5485

Command line tools

All tools are invoked with day and part as arguments, and expect input on stdin:

$ $TOOL $YEAR $DAY $PART < $INPUT

Docker image on Docker Hub

$ docker pull fredrikfornwall/advent-of-code:latest
$ echo 14 | docker run -i fredrikfornwall/advent-of-code:latest 2019 1 1
2

Running a checkout of this code

To run a solution against given input on stdin:

$ cd crates/core
$ echo 14 | cargo run -q 2019 1 1
2

Rust tool installable from crates.io

$ cargo install advent-of-code
$ echo 14 | advent-of-code 2019 1 1
2

Node tool installable from npm

$ npm install advent-of-code-wasm -g
$ echo 14 | advent-of-code-wasm 2019 1 1
2

Python tool installable from PyPi

$ pip install --upgrade advent-of-code
$ echo 14 | advent-of-code-py 2019 1 1
2

No runtime deps