Day 01
This commit is contained in:
parent
907e17ae44
commit
2fd479d02d
@ -10,9 +10,9 @@ chrono = "0.4.23"
|
|||||||
regex = "1.7.0"
|
regex = "1.7.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["a", "b", "today"]
|
default = ["part1", "part2", "today"]
|
||||||
a = []
|
part1 = []
|
||||||
b = []
|
part2 = []
|
||||||
today = []
|
today = []
|
||||||
01 = []
|
01 = []
|
||||||
02 = []
|
02 = []
|
||||||
|
2235
input/01.txt
2235
input/01.txt
File diff suppressed because it is too large
Load Diff
@ -2,4 +2,29 @@ use crate::read;
|
|||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
let input = read("01");
|
let input = read("01");
|
||||||
|
let set = vec![0];
|
||||||
|
|
||||||
|
let mut res = input.lines().fold(set, |mut acc, x|{
|
||||||
|
if x.is_empty() {
|
||||||
|
acc.push(0);
|
||||||
|
} else {
|
||||||
|
let num: i32 = x.parse().unwrap();
|
||||||
|
*acc.last_mut().unwrap() += num;
|
||||||
|
}
|
||||||
|
acc
|
||||||
|
});
|
||||||
|
res.sort();
|
||||||
|
res.reverse();
|
||||||
|
|
||||||
|
#[cfg(feature="part2")]
|
||||||
|
{
|
||||||
|
let a = res.first().unwrap();
|
||||||
|
eprintln!("Part 01: {}", *a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature="part2")]
|
||||||
|
{
|
||||||
|
let b: i32 = res[..3].iter().sum();
|
||||||
|
eprintln!("Part 02: {}", b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user