2023-11-18 17:52:07 +01:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_a(b: &mut Bencher) {
|
|
|
|
b.iter(|| part_a());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_b(b: &mut Bencher) {
|
|
|
|
b.iter(|| part_b());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn part_a() {
|
2023-11-18 16:45:50 +01:00
|
|
|
let result: u32 = include_str!("../input.txt")
|
|
|
|
.trim()
|
|
|
|
.split("\n\n")
|
|
|
|
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum())
|
|
|
|
.max()
|
|
|
|
.unwrap();
|
|
|
|
println!("A: {}", result);
|
|
|
|
}
|
2023-11-18 17:52:07 +01:00
|
|
|
|
|
|
|
fn part_b() {
|
2023-11-18 18:00:01 +01:00
|
|
|
let mut result = include_str!("../input.txt")
|
2023-11-18 17:52:07 +01:00
|
|
|
.trim()
|
|
|
|
.split("\n\n")
|
|
|
|
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum::<u32>())
|
2023-11-18 18:00:01 +01:00
|
|
|
.collect::<Vec<u32>>();
|
|
|
|
result.sort_unstable();
|
|
|
|
let total = result.into_iter().rev().take(3).sum::<u32>();
|
|
|
|
println!("B: {}", total);
|
2023-11-18 17:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
part_a();
|
|
|
|
part_b();
|
|
|
|
}
|