mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-21 15:46:28 +00:00
refactor
This commit is contained in:
parent
2b5a930d3d
commit
4a876daa71
@ -9,37 +9,45 @@ mod tests {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_a(b: &mut Bencher) {
|
fn bench_a(b: &mut Bencher) {
|
||||||
b.iter(|| part_a());
|
b.iter(|| part_a(INPUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_b(b: &mut Bencher) {
|
fn bench_b(b: &mut Bencher) {
|
||||||
b.iter(|| part_b());
|
b.iter(|| part_b(INPUT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part_a() {
|
const INPUT: &str = include_str!("../input.txt");
|
||||||
let result: u32 = include_str!("../input.txt")
|
const TEST: &str = include_str!("../test.txt");
|
||||||
|
|
||||||
|
fn part_a(input: &str) {
|
||||||
|
let result: u32 = input
|
||||||
.trim()
|
.trim()
|
||||||
.split("\n\n")
|
.split("\n\n")
|
||||||
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum())
|
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum())
|
||||||
.max()
|
.max()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("A: {}", result);
|
println!("{}", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part_b() {
|
fn part_b(input: &str) {
|
||||||
let mut result = include_str!("../input.txt")
|
let mut result = input
|
||||||
.trim()
|
.trim()
|
||||||
.split("\n\n")
|
.split("\n\n")
|
||||||
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum::<u32>())
|
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum::<u32>())
|
||||||
.collect::<Vec<u32>>();
|
.collect::<Vec<u32>>();
|
||||||
result.sort_unstable();
|
result.sort_unstable();
|
||||||
let total = result.into_iter().rev().take(3).sum::<u32>();
|
let total = result.into_iter().rev().take(3).sum::<u32>();
|
||||||
println!("B: {}", total);
|
println!("{}", total);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
part_a();
|
println!("Part A:");
|
||||||
part_b();
|
part_a(TEST);
|
||||||
|
part_a(INPUT);
|
||||||
|
|
||||||
|
println!("\nPart B:");
|
||||||
|
part_b(TEST);
|
||||||
|
part_b(INPUT);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user