From 832728e4676d4d9b2090a31417d7589abc92cfdf Mon Sep 17 00:00:00 2001
From: Christopher Bohn <bohn@unl.edu>
Date: Sat, 2 Dec 2023 06:58:55 -0600
Subject: [PATCH] Dabbling in Rust, 2023 Day 01

---
 2023/rust/Cargo.lock  |  7 +++++++
 2023/rust/Cargo.toml  |  8 ++++++++
 2023/rust/src/main.rs | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)
 create mode 100644 2023/rust/Cargo.lock
 create mode 100644 2023/rust/Cargo.toml
 create mode 100644 2023/rust/src/main.rs

diff --git a/2023/rust/Cargo.lock b/2023/rust/Cargo.lock
new file mode 100644
index 0000000..b269bcf
--- /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 0000000..335d3fb
--- /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 0000000..ffa2d8a
--- /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
-- 
GitLab