Skip to content

rbeneyton/AdventOfCode2022

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent Of Code 2022

https://adventofcode.com/2022 solutions in Rust.

Retrieve your daily input using your session cookie via:

cargo run --release -- --day <day> download --session <session>

The data is put in data/ and used directly at compile time.

To compute the execution time, use:

cargo run --release -- --day <day> execute --part <part>

To measure execution time for a particular day, use:

cargo run --release -- --day <day> benchmark --number <number> --current

double iterator::fold() can be used too, but… Code

basic logic computation.

Sadly inpt crate is slow (>500µs to parse 2500 inputs), so went back to "manual" parsing. Code

rust iterators playground… Code

range comparisons. Code

parsing harder than task. task 2 is in quick and dirty coded task 1. Code

scanning with 'appropriate' memory. naive code would have been:

use itertools::Itertools;

Solution::U64(
    input
        .chars()
        .tuple_windows()
        .enumerate()
        .skip_while(|(idx, (a, b, c, d))| ![a, b, c, d].iter().all_unique())
        .map(|(idx, _)| (idx + 4) as u64)
        .next()
        .unwrap())

which is 145µs for simple 4 wide deep scan, but mine is 24µs. Difference with 14 deep would have been huge of course… Code

Trees in rust are quite annoying to manipulate, so here is a basic hashmap based solution. Sadly this leads to too many string manipulations, we need a way to avoid them. Each part uses 165µs.

update: new version using tree, and without any String, reduced to 46µs. Code

inplace bitmask in a grid, to save as space as possible.

Code

basic movement computations.

Code

CPU register simulation, nothing special.

Code

Unkown game, plenty of subtle unsaid conditions, weird parsing for no reason, … I should have done the atcoder.jp game. Solution weren't prime factor decomposition as I first guessed, but simple lowering value by detecting invariant!

Code

path searching, basic Dijkstra

Code

parsing possible without recursion

Code

sand going down memory align to falling sand. no optimization to fill next to our current position (so… 6ms for part2!).

Code

part 1: basic geometry, but text was vague about becons already on the line. part 2 optimization: only edges of covered zones, with big step when possible, 3.5ms.

Code

part 1: astar is coming part 2:

Code

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages