advent of code 2016 in rust
Rust TeX Python Other
Permalink
Failed to load latest commit information.
day01
day02 added Cargo.lock files for posterity Jan 7, 2017
day03
day04 added Cargo.lock files for posterity Jan 7, 2017
day05 added Cargo.lock files for posterity Jan 7, 2017
day06
day07 added Cargo.lock files for posterity Jan 7, 2017
day08 cleaned up day 8 using clippy after it mysteriously started working Jan 7, 2017
day09 added Cargo.lock files for posterity Jan 7, 2017
day10 added Cargo.lock files for posterity Jan 7, 2017
day11 added Cargo.lock files for posterity Jan 7, 2017
day12
day13
day14 added Cargo.lock files for posterity Jan 7, 2017
day15 added Cargo.lock files for posterity Jan 7, 2017
day16 added Cargo.lock files for posterity Jan 7, 2017
day17
day18
day19 added Cargo.lock files for posterity Jan 7, 2017
day20
day21 added Cargo.lock files for posterity Jan 7, 2017
day22 added Cargo.lock files for posterity Jan 7, 2017
day23 added Cargo.lock files for posterity Jan 7, 2017
day24 added Cargo.lock files for posterity Jan 7, 2017
day25 added Cargo.lock files for posterity Jan 7, 2017
libaoc made libaoc::asm::step always inline for 10% speedup Jan 7, 2017
template
COPYING added copyright and license to all Dec 6, 2016
README.md cleaned up all days via clippy Jan 7, 2017
mkday.sh removed stupid symlink from mkday.sh Dec 31, 2016
process-aoc.sh

README.md

Advent Of Code 2016: Tutorial Solutions in Rust

Copyright (c) 2016 Bart Massey

Herein lie solutions to some of the problems of the 2016 Advent of Code. Advent of Code is a fantastic exercise, and I thank the author and others involved profusely for their excellent work. Thanks also to relsqui for pointing me at this last year.

The solutions are in directories named day01 through day25. For each solution, I have included commented and cleaned-up Rust code. There is a README.md in every problem directory containing descriptions, comments and usage instructions. I have also included the problem descriptions (part1.md and part2.md) and my specific input.txt for posterity.

There is also a libaoc directory containing a library used by all solutions. It includes a mishmash of AoC-specific stuff and generally-useful functionality. Please see the libaoc rustdoc for the details.

There are not many tests written for this code. I regard passing both parts of a day's problem as sufficient validation, in general. But more should be there.

I assume you have Rust running on a fast-ish UNIX box with a bunch of memory (although most everything should also work on other operating systems). A few problems are dependent on common extra packages from Cargo.

The goals of these solutions are to:

  • Provide canonical correct solutions with reasonable runtimes.

  • Illustrate reasonable solution strategies.

  • Illustrate the use of Rust in problem-solving.

I learned a ton of Rust and a little bit of software engineering I should already have known writing these.

There's also some engineering infrastructure in the form of the template directory, the mkday.sh and process-aoc.sh shell scripts and the libaoc crate. This sped up each day's setup considerably. At the beginning of day 34 I would "sh mkday.sh 34". At the end of the day I would select and copy the page source of the day 34 AoC page and then "xclipb -out | sh ../process-aoc.sh" to get markdown into the problem files for posterity.

To generate the full rustdoc for a day, simply run this highly intuitive command:

    cargo rustdoc --open -- --no-defaults --passes collapse-docs \
    --passes unindent-comments --passes strip-priv-imports

See Issue 1520 for an explanation.

These solutions deserve a much more thorough top-level description than I have the energy to write at this point. I will revise this file in the indefinite future.

There is more refactoring that should be done. Specifically:

  • The try_pat() function of days 21 and 22 should be pulled to libaoc and used in other parts as well.

I have run everything through Clippy at this point, and taken much of its advice. I have generally left idiomatic loops alone, as the iterator versions suggested by Clippy seem less clear to me. It was gratifying to see the last three days' solutions pass Clippy without warning: apparently I learned some Rust.

I am a novice Rust programmer. Feedback and pull requests are extremely welcome! Let me know what I should have done, and I'll try to make it right.


This work is licensed under the "MIT License". Please see the file COPYING in the source distribution of this software for license terms.