diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-12-06 20:34:18 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-12-06 20:40:12 +0100 |
| commit | d65dda9e5b818bc1bae6aaf6453145e08f00e5b7 (patch) | |
| tree | 04223988fe7524191be311e8eaf852fea072038e /day03/src/main.rs | |
Day01 - Day06
Diffstat (limited to 'day03/src/main.rs')
| -rw-r--r-- | day03/src/main.rs | 38 |
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); +} |
