Skip to content

petertseng/adventofcode-rs-2019

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code

These are my solutions to http://adventofcode.com

All solutions are written in Rust.

Build Status

Input

In general, all solutions can be invoked in both of the following ways:

  • Without command-line arguments, takes input on standard input.
  • With 1+ command-line arguments, reads input from the first, which must be the path to an input file. Arguments beyond the first are ignored.

Some may additionally support other ways:

  • All intcode days: May pass the intcode in ARGV as a single argument separated by commas.
  • Day 04 (Password): May pass min and max in ARGV (as two args, or as one arg joined by a hyphen).

Closing Thoughts

Sometimes cargo fmt does something I don't like, such as:

let foo = bar
    .iter()
    .map(|v| {
        // ...
        // ...
    })
    .collect();

So I restructure my code to avoid that, using one of two ways:

First possibility is to move the closure to its own line, which works if the collect line ends up being short enough.

let f = |v: T| {
    // ...
    // ...
};
let foo = bar.iter().map(f).collect();

Second possibility is to make the map the last thing by delaying the collect.

let foo = bar.iter().map(|v| {
    // ...
    // ...
});
let foo = foo.collect();