Created
December 1, 2022 12:01
-
-
Save saolsen/faf4d81cc18c2bb4c6944e8fcd846a40 to your computer and use it in GitHub Desktop.
aoc 2022 day01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let input = include_str!("day01_input.txt"); | |
let mut elf_totals = vec![]; | |
let mut total = 0; | |
for line in input.split('\n') { | |
if line == "" { | |
elf_totals.push(total); | |
total = 0; | |
} else { | |
let cals = line.parse::<i32>().unwrap(); | |
total += cals; | |
} | |
} | |
// part 1 | |
let biggest_total = elf_totals.iter().max().unwrap(); | |
println!("biggest total {}", biggest_total); | |
// part 2 | |
let mut top_3 = vec![0, 0, 0]; | |
for total in elf_totals { | |
for i in 0..top_3.len() { | |
if total > top_3[i] { | |
top_3[i] = total; | |
top_3.sort(); | |
break; | |
} | |
} | |
} | |
println!("top 3 combined {}", top_3.iter().sum::<i32>()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment