[day 1] Last commit was just part 1. Part 2 is still WIP
Some checks failed
Continuous Integration / Continuous Integration (push) Failing after 56s

This commit is contained in:
Drew Haven 2025-12-11 17:57:16 -08:00
parent ce0ba0f16c
commit 5aab5b8616
3 changed files with 49 additions and 10 deletions

30
Cargo.lock generated
View File

@ -27,6 +27,7 @@ dependencies = [
"log",
"nom",
"pico-args",
"test-env-helpers",
"tinyjson",
]
@ -279,7 +280,7 @@ checksum = "980af8b43c3ad5d8d349ace167ec8170839f753a42d233ba19e08afe1850fa69"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@ -534,7 +535,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@ -554,6 +555,17 @@ version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.111"
@ -575,6 +587,16 @@ dependencies = [
"libc",
]
[[package]]
name = "test-env-helpers"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6ab8f4822c904dadef9dd99f228f58a10d1b2c6ece06b108257e72fea72b1c6"
dependencies = [
"quote",
"syn 1.0.109",
]
[[package]]
name = "thousands"
version = "0.2.0"
@ -620,7 +642,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
"wasm-bindgen-shared",
]
@ -642,7 +664,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]

View File

@ -28,6 +28,7 @@ env_logger = "0.11.8"
log = "0.4.29"
nom = "8.0.0"
pico-args = "0.5.0"
test-env-helpers = "0.2.2"
tinyjson = "2.5.1"
# Solution dependencies

View File

@ -83,15 +83,23 @@ fn count_all_zeroes(commands: Vec<Command>) -> u64 {
for command in commands {
log::debug!("Command: {command:?}");
match command {
Command::Left(x) => position = (position.strict_sub_unsigned(x.into())),
Command::Right(x) => position = (position.strict_add_unsigned(x.into())),
Command::Left(x) => position = position.strict_sub_unsigned(x.into()),
Command::Right(x) => position = position.strict_add_unsigned(x.into()),
}
log::debug!("Position: {position:?}");
if position >= 100 || position <= 0 {
if position == 0 {
num_zeroes += 1;
position = position % 100;
}
while position > 100 {
num_zeroes += 1;
position -= 100;
log::debug!("Zeroes: {num_zeroes:?}");
}
while position < 0 {
num_zeroes += 1;
position += 100;
log::debug!("Zeroes: {num_zeroes:?}");
}
log::debug!("Position: {position:?}");
}
num_zeroes
@ -102,10 +110,18 @@ pub fn part_two(input: &str) -> Option<u64> {
Some(count_all_zeroes(commands))
}
#[cfg(test)]
use test_env_helpers::before_all;
#[before_all]
#[cfg(test)]
mod tests {
use super::*;
fn before_all() {
env_logger::init();
}
#[test]
fn test_part_one() {
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
@ -115,6 +131,6 @@ mod tests {
#[test]
fn test_part_two() {
let result = part_two(&advent_of_code::template::read_file("examples", DAY));
assert_eq!(result, None);
assert_eq!(result, Some(6));
}
}