Implement 2025 - Day 6 - Part 1

This commit is contained in:
Lol3rrr
2026-01-09 12:02:09 +01:00
parent 54dad514be
commit 56bf4644ab
3 changed files with 50 additions and 0 deletions

41
2025/06.rs Normal file
View File

@@ -0,0 +1,41 @@
---cargo
---
static CONTENT: &'static str = include_str!("./inputs/06_1.txt");
#[derive(Debug, PartialEq, Clone)]
enum Operation {
Add,
Mul,
}
fn main() {
let raw_grid: Vec<_> = CONTENT.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).map(|l| {
l.split(' ').map(|c| c.trim()).filter(|c| !c.is_empty()).collect::<Vec<_>>()
}).collect();
println!("Raw-Grid\n{:?}", raw_grid);
let mut result = 0;
let problem_count = raw_grid[0].len();
for p_idx in 0..problem_count {
let op = match raw_grid.last().map(|r| r[p_idx]) {
Some("+") => Operation::Add,
Some("*") => Operation::Mul,
other => unreachable!("Unexpected Operation {:?}", other),
};
let elem_iter = raw_grid.iter().take(raw_grid.len()-1).map(|r| r[p_idx]).map(|v| v.parse::<usize>().unwrap());
let value = match op {
Operation::Add => elem_iter.sum::<usize>(),
Operation::Mul => elem_iter.product::<usize>()
};
println!("V {}", value);
result += value;
}
println!("Result {}", result);
}