generated from Periodic/AdventOfCode-Rust
[day 1] Last commit was just part 1. Part 2 is still WIP
Some checks failed
Continuous Integration / Continuous Integration (push) Failing after 56s
Some checks failed
Continuous Integration / Continuous Integration (push) Failing after 56s
This commit is contained in:
30
Cargo.lock
generated
30
Cargo.lock
generated
@@ -27,6 +27,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"nom",
|
"nom",
|
||||||
"pico-args",
|
"pico-args",
|
||||||
|
"test-env-helpers",
|
||||||
"tinyjson",
|
"tinyjson",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -279,7 +280,7 @@ checksum = "980af8b43c3ad5d8d349ace167ec8170839f753a42d233ba19e08afe1850fa69"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.111",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -534,7 +535,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.111",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -554,6 +555,17 @@ version = "1.11.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
|
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]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.111"
|
version = "2.0.111"
|
||||||
@@ -575,6 +587,16 @@ dependencies = [
|
|||||||
"libc",
|
"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]]
|
[[package]]
|
||||||
name = "thousands"
|
name = "thousands"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -620,7 +642,7 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.111",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -642,7 +664,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.111",
|
||||||
"wasm-bindgen-backend",
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ env_logger = "0.11.8"
|
|||||||
log = "0.4.29"
|
log = "0.4.29"
|
||||||
nom = "8.0.0"
|
nom = "8.0.0"
|
||||||
pico-args = "0.5.0"
|
pico-args = "0.5.0"
|
||||||
|
test-env-helpers = "0.2.2"
|
||||||
tinyjson = "2.5.1"
|
tinyjson = "2.5.1"
|
||||||
|
|
||||||
# Solution dependencies
|
# Solution dependencies
|
||||||
|
|||||||
@@ -83,15 +83,23 @@ fn count_all_zeroes(commands: Vec<Command>) -> u64 {
|
|||||||
for command in commands {
|
for command in commands {
|
||||||
log::debug!("Command: {command:?}");
|
log::debug!("Command: {command:?}");
|
||||||
match command {
|
match command {
|
||||||
Command::Left(x) => position = (position.strict_sub_unsigned(x.into())),
|
Command::Left(x) => position = position.strict_sub_unsigned(x.into()),
|
||||||
Command::Right(x) => position = (position.strict_add_unsigned(x.into())),
|
Command::Right(x) => position = position.strict_add_unsigned(x.into()),
|
||||||
}
|
}
|
||||||
log::debug!("Position: {position:?}");
|
if position == 0 {
|
||||||
if position >= 100 || position <= 0 {
|
|
||||||
num_zeroes += 1;
|
num_zeroes += 1;
|
||||||
position = position % 100;
|
}
|
||||||
|
while position > 100 {
|
||||||
|
num_zeroes += 1;
|
||||||
|
position -= 100;
|
||||||
log::debug!("Zeroes: {num_zeroes:?}");
|
log::debug!("Zeroes: {num_zeroes:?}");
|
||||||
}
|
}
|
||||||
|
while position < 0 {
|
||||||
|
num_zeroes += 1;
|
||||||
|
position += 100;
|
||||||
|
log::debug!("Zeroes: {num_zeroes:?}");
|
||||||
|
}
|
||||||
|
log::debug!("Position: {position:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
num_zeroes
|
num_zeroes
|
||||||
@@ -102,10 +110,18 @@ pub fn part_two(input: &str) -> Option<u64> {
|
|||||||
Some(count_all_zeroes(commands))
|
Some(count_all_zeroes(commands))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use test_env_helpers::before_all;
|
||||||
|
|
||||||
|
#[before_all]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
fn before_all() {
|
||||||
|
env_logger::init();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_one() {
|
fn test_part_one() {
|
||||||
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
|
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
|
||||||
@@ -115,6 +131,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_part_two() {
|
fn test_part_two() {
|
||||||
let result = part_two(&advent_of_code::template::read_file("examples", DAY));
|
let result = part_two(&advent_of_code::template::read_file("examples", DAY));
|
||||||
assert_eq!(result, None);
|
assert_eq!(result, Some(6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user