Solution for day 24 (part 1)

main
Inga 🏳‍🌈 4 years ago
parent 4af822d729
commit b6ff7fb54b
  1. 9
      day24/Cargo.toml
  2. 35
      day24/src/main.rs

@ -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]

@ -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());
}
Loading…
Cancel
Save