more progress

This commit is contained in:
2025-09-02 09:42:27 -04:00
parent 46b91dae30
commit 1776ed8f57
6 changed files with 341 additions and 60 deletions
+10 -7
View File
@@ -5,14 +5,14 @@ use core::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 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() {
for line in lines {
let (direction, velocity) = line.split_at(1);
// println!("{line} split to ||{direction}|| and ||{velocity}||");
println!("[[[[{line}]]]] split to ||{direction}|| and ||{velocity}||");
let direction_val : i32 = velocity.parse().unwrap();
match direction {
"+" => {
@@ -25,12 +25,15 @@ fn main() {
unreachable!("Invalid direction");
}
}
print!("{working_value}\t");
println!("||{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);
for index in 0..working_value.abs() {
println!("Adding visit to {}", index + working_value);
visited_locations.insert(index + working_value, 0);
}
}
}
// BROKEN
+34
View File
@@ -0,0 +1,34 @@
use std::collections::HashMap;
use core::read_data;
fn count_letter_frequency(input: &str) -> HashMap<char, u32> {
let mut working = HashMap::new();
for current_char in input.chars() {
working.entry(current_char).and_modify(|x| *x += 1).or_insert(1);
}
working
}
fn main() {
let binding = read_data("2018_02_data.txt");
let lines = binding.lines();
let mut num_good = 0;
let mut num_three = 0;
let mut num_two = 0;
for line in lines {
let result= count_letter_frequency(line);
let mut found_2 = false;
let mut found_3 = false;
for (_, count) in result {
if count == 2 && !found_2 { found_2 = true; num_two += 1;}
if count == 3 && !found_3 { found_3 = true; num_three += 1; }
}
println!("Found {} {} in ||{line}||",
if found_2 { "" } else { "" },
if found_3 { "" } else { "" });
if found_2 && found_3 { num_good += 1; }
}
println!("Found {num_good} good boxes? / Checksum {}", num_two * num_three);
}