refactored project structure
This commit is contained in:
27
src/day06/part06a.rs
Normal file
27
src/day06/part06a.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
pub fn solve(puzzle: String) -> u64 {
|
||||
let mut iters: Vec<_> = puzzle
|
||||
.lines()
|
||||
.map(|line| line.split_whitespace())
|
||||
.collect();
|
||||
|
||||
std::iter::from_fn(move || {
|
||||
let column: Option<Vec<&str>> = iters
|
||||
.iter_mut()
|
||||
.map(|it| it.next())
|
||||
.collect::<Option<Vec<_>>>();
|
||||
|
||||
let column = column?;
|
||||
|
||||
Some((
|
||||
column[..column.len() - 1].iter().map(|v| v.parse::<u64>().unwrap()).collect::<Vec<_>>(),
|
||||
*column.last().unwrap(),
|
||||
))
|
||||
}).map(|(vals, op)| {
|
||||
match op {
|
||||
"+" => vals.iter().sum::<u64>(),
|
||||
"*" => vals.iter().product::<u64>(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}).sum::<u64>()
|
||||
}
|
||||
Reference in New Issue
Block a user