summaryrefslogtreecommitdiff
path: root/day03
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-12-06 20:34:18 +0100
committerJoel Klinghed <the_jk@spawned.biz>2025-12-06 20:40:12 +0100
commitd65dda9e5b818bc1bae6aaf6453145e08f00e5b7 (patch)
tree04223988fe7524191be311e8eaf852fea072038e /day03
Initital commitHEADmain
Day01 - Day06
Diffstat (limited to 'day03')
-rw-r--r--day03/.gitignore3
-rw-r--r--day03/Cargo.lock7
-rw-r--r--day03/Cargo.toml6
-rw-r--r--day03/src/main.rs38
4 files changed, 54 insertions, 0 deletions
diff --git a/day03/.gitignore b/day03/.gitignore
new file mode 100644
index 0000000..9cd70c0
--- /dev/null
+++ b/day03/.gitignore
@@ -0,0 +1,3 @@
+/target
+/input.txt
+/example*.txt \ No newline at end of file
diff --git a/day03/Cargo.lock b/day03/Cargo.lock
new file mode 100644
index 0000000..3ea7b86
--- /dev/null
+++ b/day03/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "day03"
+version = "0.1.0"
diff --git a/day03/Cargo.toml b/day03/Cargo.toml
new file mode 100644
index 0000000..b98f31f
--- /dev/null
+++ b/day03/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "day03"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/day03/src/main.rs b/day03/src/main.rs
new file mode 100644
index 0000000..6d86727
--- /dev/null
+++ b/day03/src/main.rs
@@ -0,0 +1,38 @@
+use std::io;
+
+fn highest_jolt(batteries: &str) -> i64 {
+ let batteries: Vec<char> = batteries.chars().collect();
+ let mut indexes = Vec::new();
+ let mut last = 0;
+ for x in 0..12 {
+ let mut index = last;
+ for i in last + 1..batteries.len() - 11 + x {
+ if batteries[i] > batteries[index] {
+ index = i;
+ }
+ }
+ indexes.push(index);
+ last = index + 1;
+ }
+ let mut tmp = String::new();
+ for i in indexes {
+ tmp.push(batteries[i]);
+ }
+ tmp.parse().unwrap()
+}
+
+fn main() {
+ let mut total = 0;
+
+ loop {
+ let mut buffer = String::new();
+ let bytes = io::stdin().read_line(&mut buffer).unwrap();
+ if bytes == 0 {
+ break;
+ }
+ let jolt = highest_jolt(buffer.trim_end());
+ total += jolt;
+ }
+
+ println!("Total: {}", total);
+}