diff --git a/day4/src/main.rs b/day4/src/main.rs index 583fad9..ced860b 100644 --- a/day4/src/main.rs +++ b/day4/src/main.rs @@ -53,13 +53,13 @@ fn main() { fn verify(passport: &HashMap) -> u32 { lazy_static! { - static ref color_match: Regex = Regex::new("#[0-9a-f]{6}").unwrap(); + static ref COLOR_MATCH: Regex = Regex::new("#[0-9a-f]{6}").unwrap(); } lazy_static! { - static ref pid_match: Regex = Regex::new("[0-9]{9}").unwrap(); + static ref PID_MATCH: Regex = Regex::new("[0-9]{9}").unwrap(); } lazy_static! { - static ref eye_colors: HashSet = { + static ref EYE_COLORS: HashSet = { let mut s = HashSet::new(); s.insert("amb".to_string()); s.insert("blu".to_string()); @@ -80,14 +80,14 @@ fn verify(passport: &HashMap) -> u32 { (2020..2031).contains(&(passport.get("eyr").unwrap().parse::().unwrap())) && passport.contains_key("hgt") && (passport.get("hgt").unwrap().ends_with("cm") && - (150..194).contains(&passport.get("hgt").unwrap().trim_right_matches("cm").parse::().unwrap()) + (150..194).contains(&passport.get("hgt").unwrap().trim_end_matches("cm").parse::().unwrap()) || passport.get("hgt").unwrap().ends_with("in") && - (59..76).contains(&passport.get("hgt").unwrap().trim_right_matches("in").parse::().unwrap()) + (59..76).contains(&passport.get("hgt").unwrap().trim_end_matches("in").parse::().unwrap()) ) && - passport.contains_key("ecl") && eye_colors.contains(passport.get("ecl").unwrap()) && - passport.contains_key("hcl") && color_match.is_match(passport.get("hcl").unwrap()) && - passport.contains_key("pid") && pid_match.is_match(passport.get("pid").unwrap()) { + passport.contains_key("ecl") && EYE_COLORS.contains(passport.get("ecl").unwrap()) && + passport.contains_key("hcl") && COLOR_MATCH.is_match(passport.get("hcl").unwrap()) && + passport.contains_key("pid") && PID_MATCH.is_match(passport.get("pid").unwrap()) { 1 } else { 0 diff --git a/day5/Cargo.toml b/day5/Cargo.toml new file mode 100644 index 0000000..b2a8b32 --- /dev/null +++ b/day5/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day5" +version = "0.1.0" +authors = ["henine "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day5/input b/day5/input new file mode 100644 index 0000000..3c51b57 --- /dev/null +++ b/day5/input @@ -0,0 +1,826 @@ +FFBBFFBRRR +FBFBBBBLRR +BFBBBBBLRR +FBBFFFBLLR +FFBBFBBLLR +FBFFFBBLRL +FBFFFFBRRL +FBBBBBFLLR +BFFFBBFLRR +FFBBFBFRLL +BFFFBFBLRL +BFBBBFBLLL +FFFBFBBLLR +FFBBBFBRLR +FFFBBBBLRR +BFFFFBFRRL +FBFFBBBRLR +BFFFFBFRLR +BFBFBFBRLR +FFBFBFFLLR +BBFBBFFRLL +BFFBBFFRRR +BBFBBFFRLR +FFBBBBFLRR +FFFFBBBLLR +FBBBBBBRRR +FBFFFBBRLL +FFBFBFFLLL +FFFBBFFRRL +BBFFBBFLRL +BFFFBBBLRR +FFBFFBFLLR +FFBFBFBRRR +FBBFBBFRLL +FFFBBFFLLR +FBFFBFBLLR +FBFFBBFLRL +BBFFFFFLRL +FBBBFFFLRR +BBFFBBBLRR +BFFFFFFRLL +BFFBFFFLRL +FFBFBBBLRR +BFBBBBBLRL +FFBBBFFRRR +BFBBFBBLLL +FFFBFBBLRL +BFFFFBBLLL +BBFFFBFRRL +BFFBFBBLRR +BFBFFFBLLL +FBFBBFBLRR +BBFFBBFRLR +FFBFFFBLLL +FBBBFBBRLL +FBFBFFBRLL +BBFBFFBLRR +BBFFBFBRLR +BBFFFFFRRR +FFFFBBFLRL +FFFBFFFRRL +BFFFBBFLRL +FFFBBBBRRR +FBBBBFBRRR +FBFBBBFLLR +BFBBBFFRRL +FFBFBFFLRL +FBBBFBFLLR +BFFBBFFRLL +BFBFFBFRRL +FBFFBFFLRR +FFBFFFFLLL +FFBBBBBRLR +FBBFBFBRRL +FFBFBBFRRL +FBFFFFFLLL +BFFBBBBRLR +FFBFBFBLLL +FBBFFBFLRR +FBBBFFFLLR +BFFFFFF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BFBRLL diff --git a/day5/src/main.rs b/day5/src/main.rs new file mode 100644 index 0000000..e6582c9 --- /dev/null +++ b/day5/src/main.rs @@ -0,0 +1,77 @@ +use std::fs::File; +use std::io::{BufReader, BufRead}; +use std::result::Result::{Err, Ok}; +use std::cmp::{max, min}; +use std::collections::HashSet; + + +fn main() { + let file = match File::open("input") { + Ok(file) => file, + Err(e) => panic!(e) + }; + + let input_buffer = BufReader::new(&file); + + let mut row = 0; + let mut row_i = 6; + let mut column = 0; + let mut col_i = 2; + + let mut max_id = 0; + + let mut filled_seats = HashSet::new(); + let mut minrow = 200; + let mut maxrow = -1; + + for rline in input_buffer.lines() { + let line = match rline { + Ok(line) => line, + Err(e) => panic!(e) + }; + + for char in line.chars() { + match char { + 'F' => { + row_i -= 1; + } + 'B' => { + row += 1 << row_i; + row_i -= 1; + } + 'R' => { + column += 1 << col_i; + col_i -= 1; + } + 'L' => { + col_i -= 1; + } + _ => panic!() + } + } + + let id = 8 * &row + &column; + + max_id = max(id, max_id); + minrow = min(row, minrow); + maxrow = max(row, maxrow); + + println!("{}: row {} column {} id {}", line, row, column, id); + filled_seats.insert((row, column)); + + row = 0; + row_i = 6; + column = 0; + col_i = 2; + } + + for r in minrow..maxrow { + for c in 0..8 { + if !filled_seats.contains(&(r, c)) { + println!("My id: {}", 8 * r + c); + } + } + } + + println!("Max id: {}", max_id); +} diff --git a/day5/test b/day5/test new file mode 100644 index 0000000..f0d065e --- /dev/null +++ b/day5/test @@ -0,0 +1,4 @@ +FBFBBFFRLR +BFFFBBFRRR +FFFBBBFRRR +BBFFBBFRLL \ No newline at end of file