summaryrefslogtreecommitdiff
path: root/day03/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'day03/src/main.rs')
-rw-r--r--day03/src/main.rs38
1 files changed, 38 insertions, 0 deletions
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);
+}