Skip to content

andyloree/AoC2021

Repository files navigation

Advent of Code 2021

Goals for 2021

  • Learning some Rust
  • Complete all 25 x 2 puzzles the days released
  • Leverage as few possible crates

Env Setup

  • WSL2 Ubuntu 20.04
  • VS Code + Remote extension
  • Rustup install curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Rust extension
  • CodeLLDB extension for debugging
  • Update rust-client.rustupPath pathin workspace settings.json to point to your wsl install path (/home/<user>/.cargo/bin/rustup)

New Day

  1. Create the our daily create:

    cargo new aoc-2021-day-#
    cd aoc-2021-day-#
    code .
  2. Press F5 then say yes to the Cargo.toml workspace configuration

  3. Add standard IO redirection for an input.txt file:

      # before "args": [],
      "stdio": ["input.txt"],
  4. Create an input.txt file, and paste in the example or puzzle input

  5. Update src/main.rs with the template:

    use std::io::{self, BufRead};
    use std::time::{Instant};
    
    fn main() {
        let start = Instant::now();
        let stdin = io::stdin();
        let lines: Vec<String> = stdin.lock().lines().flatten().collect();
    
        println!("Part 1\r\n{}", "-".repeat(10));
        // todo
    
        println!("Part 2\r\n{}", "-".repeat(10));
        // todo
    
        let duration = start.elapsed();
        println!("Total execution time: {:?}", duration);
    }
  6. Get to solving

Tips from along the way...

Standard IO redirection with Run in vscode

Somewhat difficult to find, but CodeLLDB allows for standard IO redirection using the stdio in the launch.json.

  • stdin only: "stdio": ["input.txt"]
  • stdout and stderr: "stdio": [null, "out.txt", "err.txt"]

Perf profiler in WSL2 Ubuntu

Due to customer kernel within WSL2, you have to compile from the accessible kernel source.

  1. sudo apt install build-essential flex bison libssl-dev libelf-dev
  2. git clone --depth=1 https://github.com/microsoft/WSL2-Linux-Kernel.git
  3. cd WSL2-Linux-Kernel/tools/perf
  4. make
  5. cp perf /usr/bin/perf
  6. Copy the stackcollapse-perf.pl script to /usr/local/bin/stackcollapse-perf.pl
  7. chmod 775 /usr/local/bin/stackcollapse-perf.pl
  8. Copy the rust-unmangle sed script to /usr/local/bin/rust-unmangle
  9. Copy the flamegraph.pl script to /usr/local/bin/flamegraph.pl
  10. chmod 755 /usr/local/bin/flamegraph.pl

Releases

No releases published

Packages

No packages published

Languages