24 stable releases

new 2019.12.68 Sep 18, 2020
2019.12.67 Sep 17, 2020

#102 in Rust patterns

Download history 65/week @ 2020-09-05 196/week @ 2020-09-12

80 downloads per month

MIT license

250KB
7K SLoC

Build Netlify Status Crates.io Docker Hub npm PyPi

Advent of Code solutions in Rust

This repository contains solutions to Advent of Code problems in Rust.

Libraries

The solve(year, day, part, input) library function is published on 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 a HTTP endpoint running on Netlify Functions (using Node.js and WebAssembly) that can be used as follows:

$ curl --data-binary 14 "https://aoc.fornwall.net/.netlify/functions/solve?year=2019&day=1&part=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/.netlify/functions/solve?year=2019&day=2&part=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

Dependencies

~445KB