diff --git a/day24/Cargo.toml b/day24/Cargo.toml new file mode 100644 index 0000000..363fc6b --- /dev/null +++ b/day24/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day24" +version = "0.1.0" +authors = ["inga-lovinde <52715130+inga-lovinde@users.noreply.github.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day24/src/main.rs b/day24/src/main.rs new file mode 100644 index 0000000..fe7cff4 --- /dev/null +++ b/day24/src/main.rs @@ -0,0 +1,35 @@ +use std::collections::HashSet; +use std::io::{self, BufRead}; + +fn main() { + let stdin = io::stdin(); + let mut changed_tiles = HashSet::new(); + for line_result in stdin.lock().lines() { + let processed_line = line_result.unwrap().replace("nw", "7").replace("ne", "9").replace("sw", "1").replace("se", "3"); + let mut x = 0; + let mut y = 0; + for ch in processed_line.chars() { + x += match ch { + 'e' => 2, + 'w' => -2, + '9' | '3' => 1, + '7' | '1' => -1, + _ => 0, + }; + y += match ch { + '9' | '7' => 1, + '3' | '1' => -1, + _ => 0, + }; + } + + let tile = (x, y); + if changed_tiles.contains(&tile) { + changed_tiles.remove(&tile); + } else { + changed_tiles.insert(tile); + } + } + + println!("{}", changed_tiles.len()); +}