Compare commits

...

3 Commits
main ... day-1

Author SHA1 Message Date
07391a83db Update LICENSE
Forgot that the default license provided by Gitea is a template and needs to be filled out *facepalm*
2022-12-03 15:33:47 +01:00
5c63fdf294 Solve Part 2 2022-12-01 18:51:42 +01:00
f95bd1267f Solved Part 1 2022-12-01 18:37:10 +01:00
3 changed files with 2299 additions and 3 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) <year> <owner> Copyright (c) 2022, apio
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

2251
src/input.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,48 @@
fn main() { // https://adventofcode.com/2022/day/1
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();
} }