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="aoc2021"
version = "0.1.0"
edition = "2024"
[dependencies]
core = { path = "../core" }
+26
View File
@@ -0,0 +1,26 @@
use core::read_data;
fn dips(input: &str) -> u32 {
let mut last_reading = 0;
let mut counter = 0;
for line in input.lines() {
let current_reading: u32 = line.parse().unwrap();
if last_reading <= current_reading {
counter += 1;
println!("Increase from {} to {}", current_reading, last_reading);
}
last_reading = current_reading;
}
// first is always 0
counter -= 1;
println!("There were {counter} decreasing readings.");
counter
}
fn main() {
let binding = read_data("2021_01_data.txt");
let lines = binding;
println!("Test 1 -> {}", dips("199\n200\n208\n210\n200\n207\n240\n269\n260\n263"));
// println!("Found {}", dips(lines.as_str()));
}
// 1791
+33
View File
@@ -0,0 +1,33 @@
use core::read_data;
enum CardinalDirection {
North,
East,
South,
West
}
fn main() {
let mut facing = CardinalDirection::North;
let (mut current_x, mut current_y) = (0u32, 0u32);
let binding = read_data("2021_02_data.txt");
let steps = binding.lines();
for step in steps {
let (direction, velocity) = step.split_once(" ").unwrap();
let velocity: u32 = velocity.parse().unwrap();
match direction {
"forward" => {
println!("Move forward {}", velocity);
},
"down" => {
println!("Move Down {}", velocity);
},
"up" => {
println!("Move UP {}", velocity);
},
_ => {
unreachable!("Invalid direction");
}
}
}
}