Finished day 2

This commit is contained in:
2022-12-03 08:53:34 +00:00
parent bc0ba67c16
commit 8dfa008aae
4 changed files with 2641 additions and 6 deletions

View File

@@ -1,10 +1,10 @@
fn elf_calorie_counts(input: &String) -> Vec<u64> {
fn elf_calorie_counts(input: &str) -> Vec<u64> {
input.split("\n\n").map(|elf| {
elf.split_whitespace().map(|meal| meal.parse().unwrap_or(0)).sum()
}).collect()
}
pub fn part_1(input: &String) -> u64 {
pub fn part_1(input: &str) -> u64 {
let mut elf_calorie_counts= elf_calorie_counts(input);
elf_calorie_counts.sort_unstable();
@@ -12,7 +12,7 @@ pub fn part_1(input: &String) -> u64 {
elf_calorie_counts.pop().unwrap()
}
pub fn part_2(input: &String) -> u64 {
pub fn part_2(input: &str) -> u64 {
let mut elf_calorie_counts= elf_calorie_counts(input);
elf_calorie_counts.sort_unstable();