2016, 2017, 2018, 2024 puzzle progress

This commit is contained in:
2025-10-08 13:17:46 -04:00
parent af075edb24
commit e1bdbe21c8
21 changed files with 3658 additions and 43 deletions
+20 -6
View File
@@ -9,27 +9,41 @@
//
use std::collections::HashMap;
use std::str;
use core::read_data;
fn is_valid(input: &str) -> bool {
let mut is_valid = true;
let parts = input.split(' ');
let mut working = HashMap::new();
let expected_parts = parts.clone().count();
let mut working: HashMap<&str, u32> = HashMap::new();
for part in parts {
working.entry(part);
*working.entry(part).or_insert(0);
}
true
println!("Working has {} entries.", working.keys().len());
expected_parts == working.keys().len()
}
fn main() {
// let binding = read_data("2017_04_data.txt");
let binding = read_data("2017_04_data.txt");
let params = vec![
("aa bb cc dd ee", true),
("aa bb cc dd aa", false),
("aa bb cc dd aaa", true)
];
for (input, expected) in params {
let actual = is_valid(input);
println!("||{input}|| was expected to be {expected} but was {actual}");
println!("{}\t||{input}|| expected to be {expected} and was {actual}",
if actual == expected { '✔' } else { '❌' }
);
}
}
let mut num_valid = 0;
for to_check in binding.lines() {
if is_valid(to_check) { num_valid += 1 }
}
println!("Found {num_valid} valid entries.");
}
// 451
+27
View File
@@ -0,0 +1,27 @@
use core::read_data;
fn main() {
let mut instructions = vec![];
let mut instruction_pointer: i32 = 0;
let input = "0\n3\n0\n1\n-3";
//let input = read_data("2017_05_data.txt");
let lines = input.lines();
let num_lines = lines.clone().count();
println!("Found {num_lines}");
for line in lines {
let value = line.parse::<i32>().unwrap();
instructions.push(value);
// println!("Line = [{value}]");
}
println!("Instructions loaded...Executing.");
let mut should_exit = false;
while !should_exit {
if instruction_pointer < 0 || instruction_pointer > num_lines as i32 { should_exit = true }
// find out the instruction we have at the current pointer...
let current_instruction = instructions[instruction_pointer as usize];
instructions[instruction_pointer as usize] += 1;
instruction_pointer += current_instruction;
}
println!("Final IP value is {instruction_pointer}");
}