day1: Extract input parsing to lib

This commit is contained in:
jazzpi 2022-12-12 20:05:28 +01:00
parent f7fe704a12
commit 84ee26264b
4 changed files with 11 additions and 4 deletions

View File

@ -9,4 +9,3 @@ edition = "2021"
[[bin]]
name = "d1p1"
path = "src/d1p1.rs"

8
src/bin/d1p1.rs Normal file
View File

@ -0,0 +1,8 @@
use aoc22::day1;
fn main() {
let elves = day1::read_elves();
let max = elves.iter().max().unwrap();
println!("The elf with the most calories is carrying {} cal", max);
}

View File

@ -1,6 +1,6 @@
use std::io;
fn main() {
pub fn read_elves() -> Vec<u32> {
println!("What's the calorie list?");
let lines = io::stdin().lines();
let mut was_empty = false;
@ -23,6 +23,5 @@ fn main() {
elves.push(prev_calories + calories);
}
let max = elves.iter().max().unwrap();
println!("The elf with the most calories is carrying {} cal", max);
elves
}

1
src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod day1;