use std::io; fn highest_jolt(batteries: &str) -> i64 { let batteries: Vec = 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); }