moved code around so each year is a package.

This commit is contained in:
2025-08-29 16:14:42 -04:00
parent 8aa7fe572f
commit 46b91dae30
67 changed files with 246 additions and 77 deletions
+7
View File
@@ -0,0 +1,7 @@
[package]
name="aoc2018"
version = "0.1.0"
edition = "2024"
[dependencies]
core = { path = "../core" }
+30
View File
@@ -0,0 +1,30 @@
// Starting with a frequency of zero, what is the resulting frequency after all of the changes in
// frequency have been applied?
use std::collections::HashMap;
use core::read_data;
fn main() {
let mut running_total = 0i32;
let binding = read_data("2018_01_data.txt");
let lines = binding.lines();
for line in lines {
let (direction, value) = line.split_at(1);
let num_val: i32 = value.parse().unwrap();
println!("Line = {line} -> {direction}||{num_val}");
match direction {
"-" => {
running_total -= num_val;
}
"+" => {
running_total += num_val;
}
_ => {
unreachable!("bad location");
}
}
}
println!("Final value = {running_total}");
}
// 533
+36
View File
@@ -0,0 +1,36 @@
// do part 1a but figure out the first repeated value
use std::collections::HashMap;
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 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