Files
aoc/src/bin/2018_01b.rs
T
tmerritt 8aa7fe572f lots of stuff ive done.
maybe a status would be good?
2025-08-29 08:12:33 -04:00

36 lines
1.1 KiB
Rust

// do part 1a but figure out the first repeated value
use std::collections::HashMap;
use aoc::read_data;
fn main() {
let mut visited_locations: HashMap<i32, i32> = HashMap::from([(0, 0)]);
// let binding = read_data("2018_01_data.txt");
// let lines = binding.lines();
let lines = "-6\n+3\n+8\n+5\n-6".to_string();
let mut working_value = 0i32;
for line in lines.lines() {
let (direction, velocity) = line.split_at(1);
// println!("{line} split to ||{direction}|| and ||{velocity}||");
let direction_val : i32 = velocity.parse().unwrap();
match direction {
"+" => {
working_value += direction_val;
}
"-" => {
working_value -= direction_val;
}
_ => {
unreachable!("Invalid direction");
}
}
print!("{working_value}\t");
if let Some(found) = visited_locations.get(&working_value) {
println!("GET SUCCESS -> {working_value} / {found}");
break;
}
visited_locations.insert(working_value, 0);
}
}
// BROKEN