1
0
mirror of https://gitlab.com/MisterBiggs/aoc_2022-rust.git synced 2025-06-16 15:17:15 +00:00

day 1 complete

This commit is contained in:
Anson 2022-12-01 15:59:11 -07:00
parent 971581dd85
commit a12c497551

View File

@ -8,44 +8,79 @@ pub fn run() {
println!("\tPart 2: {}", part2(&input)); println!("\tPart 2: {}", part2(&input));
} }
fn part1(food_list: &str) -> isize { fn part1(food_input: &str) -> usize {
todo!() food_input
.split("\n\n")
.collect::<Vec<&str>>()
.into_iter()
.map(|elf| {
elf.split_whitespace()
.map(|food| food.parse::<usize>().unwrap())
.sum()
})
.collect::<Vec<usize>>()
.into_iter()
.max()
.unwrap()
} }
fn part2(food_list: &str) -> usize { fn part2(food_input: &str) -> usize {
todo!() let mut elves_calories = food_input
.split("\n\n")
.collect::<Vec<&str>>()
.into_iter()
.map(|elf| {
elf.split_whitespace()
.map(|food| food.parse::<usize>().unwrap())
.sum()
})
.collect::<Vec<usize>>();
elves_calories.sort_by(|l, r| r.cmp(l));
elves_calories[..3].iter().sum::<usize>()
} }
// #[cfg(test)] #[cfg(test)]
// mod tests { mod tests {
// use super::*; use super::*;
// #[test] #[test]
// fn test_1() { fn test_1() {
// let mut input = "(())".to_string(); let input = "1000
// assert_eq!(part1(&input), 0); 2000
3000
// input = "()()".to_string(); 4000
// assert_eq!(part1(&input), 0);
// input = "(((".to_string(); 5000
// assert_eq!(part1(&input), 3); 6000
// input = "(()(()(".to_string(); 7000
// assert_eq!(part1(&input), 3); 8000
9000
// input = "())".to_string(); 10000";
// assert_eq!(part1(&input), -1);
// input = ")())())".to_string(); assert_eq!(part1(input), 24000);
// assert_eq!(part1(&input), -3); }
// }
// #[test] #[test]
// fn test_2() { fn test_2() {
// let mut input = ")".to_string(); let input = "1000
// assert_eq!(part2(&input), 1); 2000
3000
// input = "()())".to_string(); 4000
// assert_eq!(part2(&input), 5);
// } 5000
// } 6000
7000
8000
9000
10000";
assert_eq!(part2(input), 45000);
}
}