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="aoc2019"
version = "0.1.0"
edition = "2024"
[dependencies]
core = { path = "../core" }
+20
View File
@@ -0,0 +1,20 @@
#![feature(int_roundings)]
use core::read_data;
fn fuel_calc(input: u32) -> u32 {
input.div_floor(3).saturating_sub(2)
}
fn main() {
let mut working_value = 0;
let binding = read_data("2019_01_data.txt");
let lines = binding.lines();
for line in lines {
let number: u32 = line.parse().unwrap();
// println!("Line -> {line} - [{number}]");
working_value += fuel_calc(number);
}
println!("Working Value without self-> {working_value}");
}
// 3228475
+28
View File
@@ -0,0 +1,28 @@
#![feature(int_roundings)]
use core::read_data;
fn fuel_calc(input: u32) -> u32 {
input.div_floor(3).saturating_sub(2)
}
fn total_fuel(mut mass: u32) -> u32 {
let mut total = 0;
while mass > 0 {
mass = fuel_calc(mass);
total += mass;
}
total
}
fn main() {
let mut working_value = 0;
let binding = read_data("2019_01_data.txt");
let lines = binding.lines();
for line in lines {
let number: u32 = line.parse().unwrap();
working_value += total_fuel(number);
}
println!("Working Value without self-> {working_value}");
}
// 4839845
+9
View File
@@ -0,0 +1,9 @@
use core::read_data;
fn main() {
let directions = read_data("2019_02_data.txt").split(", ");
for direction in directions {
}
}
+35
View File
@@ -0,0 +1,35 @@
fn is_valid(input: i32) -> bool {
let mut has_double = false;
let mut last_digit: Option<i32> = None;
for current_char in input.to_string().chars() {
let current_digit = current_char.to_digit(10).unwrap() as i32;
if let Some(last) = last_digit {
if last > current_digit {
// Digits decrease → invalid
return false;
}
if last == current_digit {
has_double = true;
}
}
last_digit = Some(current_digit);
}
has_double
}
fn main() {
for input in 136818..=685979 {
print!("START [[{input}]]");
if is_valid(input) {
println!("Success at {input}");
break;
}
}
}
// 136888 bad
// 145678 bad
// 136888
+31
View File
@@ -0,0 +1,31 @@
fn is_valid(input: i32) -> bool {
let mut has_double = false;
let mut last_digit: Option<i32> = None;
for current_char in input.to_string().chars() {
let current_digit = current_char.to_digit(10).unwrap() as i32;
if let Some(last) = last_digit {
if last > current_digit {
// Digits decrease → invalid
return false;
}
if last == current_digit {
has_double = true;
}
}
last_digit = Some(current_digit);
}
has_double
}
fn main() {
for input in 136818..=685979 {
if is_valid(input) {
println!("Success at {input}");
break;
}
}
}