Day 1
commit
b7e687e685
@ -0,0 +1 @@
|
||||
/target
|
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aoc2022"
|
||||
version = "0.1.0"
|
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "aoc2022"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,9 @@
|
||||
unstable_features = true
|
||||
hard_tabs = true
|
||||
max_width = 80
|
||||
imports_granularity = 'Crate'
|
||||
group_imports = 'StdExternalCrate'
|
||||
format_strings = true
|
||||
wrap_comments = true
|
||||
blank_lines_lower_bound = 0
|
||||
blank_lines_upper_bound = 2
|
@ -0,0 +1,44 @@
|
||||
pub mod a {
|
||||
static INPUT: &str = include_str!("inputs/day1a.txt");
|
||||
|
||||
pub fn go() {
|
||||
let input = INPUT;
|
||||
let max = input
|
||||
.split("\n\n")
|
||||
.map(|elf_cals_str| {
|
||||
elf_cals_str
|
||||
.split('\n')
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(|cal_str| cal_str.parse::<u32>().unwrap())
|
||||
.sum::<u32>()
|
||||
})
|
||||
.max()
|
||||
.unwrap();
|
||||
|
||||
println!("{}", max);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod b {
|
||||
static INPUT: &str = include_str!("inputs/day1a.txt");
|
||||
|
||||
pub fn go() {
|
||||
let input = INPUT;
|
||||
let mut cals: Vec<_> = input
|
||||
.split("\n\n")
|
||||
.map(|elf_cals_str| {
|
||||
elf_cals_str
|
||||
.split('\n')
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(|cal_str| cal_str.parse::<u32>().unwrap())
|
||||
.sum::<u32>()
|
||||
})
|
||||
.collect();
|
||||
|
||||
cals.sort_by(|a, b| a.cmp(b).reverse());
|
||||
|
||||
let total = cals.iter().take(3).sum::<u32>();
|
||||
|
||||
println!("{}", total);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,5 @@
|
||||
mod day1;
|
||||
|
||||
fn main() {
|
||||
day1::b::go();
|
||||
}
|
Loading…
Reference in New Issue