Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
bd71dfb6bb |
2251
src/input.txt
2251
src/input.txt
File diff suppressed because it is too large
Load Diff
49
src/main.rs
49
src/main.rs
@ -1,48 +1,3 @@
|
|||||||
// https://adventofcode.com/2022/day/1
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
const DATA: &'static str = include_str!("input.txt");
|
|
||||||
|
|
||||||
fn parse_calories_per_elf(elf: &str) -> i32 {
|
|
||||||
let mut elf_sum = 0;
|
|
||||||
for food_item in elf.split("\n")
|
|
||||||
{
|
|
||||||
elf_sum += food_item.parse().unwrap_or(0);
|
|
||||||
}
|
|
||||||
elf_sum
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn part1() {
|
|
||||||
let mut highest_sum = 0;
|
|
||||||
for elf in DATA.split("\n\n")
|
|
||||||
{
|
|
||||||
let elf_sum = parse_calories_per_elf(elf);
|
|
||||||
if elf_sum > highest_sum {
|
|
||||||
highest_sum = elf_sum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!("The elf carrying the most calories carries {} calories", highest_sum);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn part2() {
|
|
||||||
let mut elves: Vec<i32> = Vec::new();
|
|
||||||
|
|
||||||
for elf in DATA.split("\n\n")
|
|
||||||
{
|
|
||||||
let elf_sum = parse_calories_per_elf(elf);
|
|
||||||
elves.push(elf_sum);
|
|
||||||
}
|
|
||||||
|
|
||||||
elves.sort();
|
|
||||||
|
|
||||||
// Get the 3 elves carrying more calories
|
|
||||||
let slice = &elves[elves.len()-3 ..];
|
|
||||||
|
|
||||||
println!("The 3 elves carrying the most calories carry {} calories", slice.iter().sum::<i32>());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main()
|
|
||||||
{
|
|
||||||
//part1();
|
|
||||||
part2();
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user