Compare commits

...

3 Commits

Author SHA1 Message Date
beeb89a2f6 Day 02 boilerplate 2022-12-01 07:36:30 +01:00
64851dd68b Fix part 1 feature flag 2022-12-01 07:23:51 +01:00
2fd479d02d Day 01 2022-12-01 07:14:55 +01:00
5 changed files with 2285 additions and 5 deletions

View File

@ -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 = []

File diff suppressed because it is too large Load Diff

View File

@ -2,4 +2,29 @@ use crate::read;
pub fn run() { pub fn run() {
let input = read("01"); let input = read("01");
let elves = vec![0];
let mut elves = input.lines().fold(elves, |mut acc, x|{
if x.is_empty() {
acc.push(0);
} else {
let num: i32 = x.parse().unwrap();
*acc.last_mut().unwrap() += num;
}
acc
});
elves.sort();
elves.reverse();
#[cfg(feature="part1")]
{
let a = elves.first().unwrap();
eprintln!("Part 01: {}", *a);
}
#[cfg(feature="part2")]
{
let b = elves[..3].iter().sum::<i32>();
eprintln!("Part 02: {}", b);
}
} }

20
src/day02/mod.rs Normal file
View File

@ -0,0 +1,20 @@
use crate::read;
pub fn run() {
let input = read("02");
let lines = input.lines();
#[cfg(feature="part1")]
{
let a = "TODO";
eprintln!("Day 2, Part 01: {}", a);
}
#[cfg(feature="part2")]
{
let b = "TODO";
eprintln!("Day 2, Part 02: {}", b);
}
}

View File

@ -2,6 +2,7 @@ use std::path::Path;
use std::time::Instant; use std::time::Instant;
use chrono::prelude::*; use chrono::prelude::*;
mod day01; mod day01;
mod day02;
fn main() { fn main() {
let today = Local::now().day(); let today = Local::now().day();
@ -10,8 +11,7 @@ fn main() {
day01::run(); day01::run();
} }
if cfg!(feature ="day02") || (cfg!(feature ="today") && today == 2) { if cfg!(feature ="day02") || (cfg!(feature ="today") && today == 2) {
todo!() day02::run();
//day02::run();
} }
println!("Finished, time taken: {:?}", now.elapsed()) println!("Finished, time taken: {:?}", now.elapsed())
} }