diff --git a/2023/rust/Cargo.lock b/2023/rust/Cargo.lock new file mode 100644 index 0000000000000000000000000000000000000000..b269bcfb8bc4d9969a3b232a5dfb3b6a5dbd6e51 --- /dev/null +++ b/2023/rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "advent_of_code" +version = "0.1.0" diff --git a/2023/rust/Cargo.toml b/2023/rust/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..335d3fbbd39304a6d41a29019f6e78cadb01f5a6 --- /dev/null +++ b/2023/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "advent_of_code" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2023/rust/src/main.rs b/2023/rust/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..ffa2d8a82223753572b713e4d463c9a80e03fd55 --- /dev/null +++ b/2023/rust/src/main.rs @@ -0,0 +1,36 @@ +fn day01(data: Vec<&str>) -> u32 { + let mut values: Vec<u32> = Vec::new(); + for datum in data { + let mut first_digit: Option<u32> = None; + let mut last_digit: Option<u32> = Option::from(0); + for character in datum.chars() { + if character.is_digit(10) { + if first_digit == None { + first_digit = character.to_digit(10); + } + last_digit = character.to_digit(10); + } + } + if first_digit == None { + first_digit = Option::from(0); + } + values.push(10 * first_digit.expect("this shouldn't happen") + last_digit.expect("this shouldn't happen")); + } + let mut value: u32 = 0; + return loop { + if values.is_empty() { + break value; + } else { + value += values.pop().expect("this really shouldn't happen"); + } + } +} + +fn main() { + println!("Hello, world!"); + let day01a_data = vec!["1abc2", "pqr3stu8vwx", "a1b2c3d4e5f", "treb7uchet"]; + let day01b_data = vec!["two1nine", "eightwothree", "abcone2threexyz", "xtwone3four", + "4nineeightseven2", "zoneight234", "7pqrstsixteen"]; + println!("{}", day01(day01a_data)); + // day01(day01b_data); +} \ No newline at end of file