GithubHelp home page GithubHelp logo

advent_of_code_2022's Introduction

Eric's Advent of Code 2022 Solutions

The Blog

For the last two years, I've blogged my approaches to the Advent of Code puzzles on my personal site. Assuming I hold true to form, each blog post will include code and commentary on my thinking behind the approach, my thoughts about the puzzles, and vain attempts at wit.

Project Structure

This year, I'm using Rust! I solved 2019's puzzles in Rust after the fact (it's how I learned Rust to begin with), but this year I'll solve each day in Rust first. I've set up folders for each day's code and input files like so:

<project root>
├─benches
│ └─all_days.rs
├─input
│ └─XX
│   ├─input.txt
│   └─test.txt
├─src
│ ├─dayXX
│ │ ├─input.rs
│ │ ├─mod.rs
│ │ ├─part1.rs
│ │ └─part2.rs
│ ├─bin.rs
│ └─lib.rs
├─Cargo.toml
└─README.md

There are a few organizational notes to point out here:

  • The mod.rs file for each day defines Input as a type alias for the type the input file will be parsed into, and a convenience function run(_: Part) -> Output that reads in the input and solves for either part one or part two, depending on the variant of Part that is passed and returns the result as an Output (for consistency). This file also contains the tests that cofirm the answer once it has been found.

  • Output is an enum with variants for u32, i32, u64, i64, and String`. This allows the binary to expect the same (printable) type from each day's solution.

  • Input files are being included in each day's input.rs via the include_str!() macro, which means parsing will be on the file contents as one long, newline-separated, string slice. The main entrypoint for input parsing is the read() -> Input function which takes no arguments (relying on the included INPUT constant) and returns the parsed input file.

  • The part1.rs and part2.rs files each contain a solve(_: &Input) -> Output function that takes a reference to the parsed input and returns the solution for that part of that day.

    Usage

    Most of the functionality of this project shell is best accessed via cargo (though you can install the project if you really want to).

    • cargo test to run the tests. Full documentation for that command here
    • cargo bench to run the benchmarks. Full documentation for that command here
    • cargo run to run the first day's solutions and print the results. cargo run <number> to run the day's solutions and print the results.

advent_of_code_2022's People

Contributors

ericwburden avatar williammartin avatar

Watchers

 avatar  avatar  avatar

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.