This commit is contained in:
Dan Ballard 2020-12-06 23:06:49 -08:00
parent 96afcc4395
commit 6c06cbcce4
4 changed files with 859 additions and 1 deletions

814
inputs/05-01.txt Normal file
View File

@ -0,0 +1,814 @@
FBFBBBFRLL
BFFFBFFRRR
BBFBFFFLLR
FBFFFBFLRR
FBFFBFBLLR
BFBBFBBRLL
BFFFFFFRLR
FBBBBFFLLR
FFBBFFFLRL
FFBFBBFLLR
FBFFFBBRRR
FBFFBFBLRR
FBBFBFFRLR
FBBBFBFRLL
FFBFFBBRLR
FBFBBBFRRL
BFFBBBFRRR
FBFBBBBLLR
FFBFFBBLLL
BFFBFBBLLR
BFFBFBBRLR
BFFBBBBLLL
FBBBBFBLLR
FFBFBBBLRR
FFBFBBFLRR
FFFBFBBRRL
FFFFFBBRLL
BFFFBFFLRR
FFFBFBBRLR
FBFFBBFLLR
BFBFFBBRRR
FBBFBBFLRL
BFBBFBFRRR
BFFFBBBLRL
BBFFFBFLLR
BFFFFBFLRR
BFFBFFBLLL
FFBBFBFRRR
BFBFFFBLLL
FBFBFFFRRR
BFBFBBBLLL
BFFFBBFLLL
BFBFFFBLLR
BFFBBBFRRL
FFFBBFFLLR
BFFBBBFLRR
FBFFBBBRLR
FBBFBBFLRR
FBBFFBFRRR
FBBFBBBRRL
FFFBFFBRRL
FBFBFFBRLL
FBFFBBFRLL
BFBFBFFRLL
FBFBFFFRLR
BFBFFBBRRL
FFBBFFBRRR
BFFBFBBLRL
FFBFBFBLLL
BBFFFBFRLL
FBFBBBFRRR
BFFBBFFLRR
BFBBFFBLRL
BFFFFFBLLL
BBFFFFFRLR
FBBFFBFRLL
FFBFBFFRRR
BFBBBBFLRR
BFFBBFFRLL
BFBBFFBLLL
BFFFFFBRRR
FBBFFFBLRL
FFFBBBFRLR
FFBBBFBRRL
BFFFBBBRRL
FFBFBFBRRR
FBBBBBFRRR
BBFBFFFRLL
FBFFFBBLRR
FBFBFFBRRR
BFBFBFBRLR
FBBBFFFRRL
BFBFFFBRLL
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LLR
FFBBFFFLLL
BFFBBBFRLL
FFBBBBFRLL
FFFFBFFLRR
FFBBBBBLRL
FBBBBBBLRR
FBBFFFBLLR
BBFFFBBRLL
BFFBBFFLRL
FFFBFBFRRR
FBFBFBBLLL
FBBBBBFRLL
FBBBBBBRRL
FBFBBBBRRL
FBFFBFFRRL
BFFFBBFLLR
BFFBFFFLRR
BFFBBFBLRR
FFFFBFBRLL
BFFBFFFLRL
FFBFFFBLRL
FBBFFFBLRR
BFBBBFFLRL
FBFFBBFLRL
BFFFBBBRLR
BFFBFBBRRR
BFFFFFBLRL
BBFBFFFLRL
BFBFBBFRRL
BBFFBFFLRR
FBFBFBBLRL
BFBFBBFRLR
FFFBBBBRRR
FBFFFFBLLR
FBFBBFFRLL
BFBFFBFRRR
FFFBFFBLLR
FBFBFBFLRL
FBBFBBBRLR
FFFBFBBLLR
FFBBFFFRLL
BFBFFBBRLR
BBFFFFBLLL
FFBBBFFRRR
BFFBFFFRLR
FFBFFBBLRL
FBBBFFBRRR
BFBFBBFRLL
BFBBBBFRRL
BFBBFFBRLL
BBFFFBBLRL
FFBBBBFRRR
BBFFFBFRRR
BFBFFFFLRR
FFFBFBBLRR
BFFBBFBRRL
FBBFBBBRRR
FBFBFFFLRL
BFBBFBFRLR
FFFBFFFLRL
FFBBBFBRRR
FBBFFBBRRR
BBFFFBBLLR
FFFBFFBLRL
FFBFBBBRRL
FFBBBFFLLR
FBFFBBFRLR
FBFFFBFLRL
FFBBFBBRRL
FFFBBFFRRL
FBBFBBFRLR
FBFBBFFRRR
FFFFBFFRRR
BFFFFFBLRR
BBFFFFBRRL
FBBBFFBLRR
BFFBFBFRLL
FFBFFFBRRL
FFBFBFBLLR

42
src/aoc05/mod.rs Normal file
View File

@ -0,0 +1,42 @@
use std::error::Error;
use std::fs;
use std::str;
use std::i64;
use std::collections::HashMap;
pub fn both(filename: &str) -> Result<(), Box<dyn Error>> {
let contents = fs::read_to_string(filename)?;
let mut lowest_sid = 2000;
let mut highest_sid = 0;
let mut sids: HashMap<i64, bool> = HashMap::new();
for line in contents.lines() {
let mut bstr = line.replace("B", "1");
bstr = bstr.replace("F", "0");
bstr = bstr.replace("R", "1");
bstr = bstr.replace("L", "0");
let sid = i64::from_str_radix(&bstr, 2).unwrap();
sids.insert(sid, true);
if sid > highest_sid {
highest_sid = sid;
}
if sid < lowest_sid {
lowest_sid = sid;
}
}
let mut my_sid = 0;
for i in lowest_sid..highest_sid {
if !sids.contains_key(&i) {
my_sid = i;
break
}
}
println!("Highest seat id seen: {}", highest_sid);
println!("Missing seat id (so mine!): {}", my_sid);
Ok(())
}

View File

@ -2,3 +2,4 @@ pub mod aoc01;
pub mod aoc02;
pub mod aoc03;
pub mod aoc04;
pub mod aoc05;

View File

@ -11,6 +11,7 @@ fn main() {
2 => advent_of_code::aoc02::both("./inputs/02-01.txt"),
3 => advent_of_code::aoc03::both("./inputs/03-01.txt"),
4 => advent_of_code::aoc04::both("./inputs/04-01.txt"),
5 => advent_of_code::aoc05::both("./inputs/05-01.txt"),
_ => Err(format!("unsupported day {}", day).into()),
};