Advent 2025 Day 1 Part 2, Day 6 Part 1
This commit is contained in:
parent
8d5d5fd758
commit
151a0ca82f
7 changed files with 110 additions and 32 deletions
34
advent_of_code_2025/src/day6/part2.rs
Normal file
34
advent_of_code_2025/src/day6/part2.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
pub fn solve(input: &str) {
|
||||
let lines = input.lines().collect::<Vec<_>>();
|
||||
|
||||
let rows = lines[..(lines.len() - 1)].iter().map(|line| {
|
||||
line.split(" ").filter(|str| !str.is_empty()).map(|num| { num.parse::<u64>().unwrap() }).collect::<Vec<_>>()
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let operators = lines.last().unwrap().bytes().filter(|b| *b != b' ').collect::<Vec<_>>();
|
||||
|
||||
// println!("rows: {rows:?}");
|
||||
// println!("operators: {operators:?}");
|
||||
|
||||
let mut sum_of_operations = 0;
|
||||
|
||||
for (idx, operator) in operators.iter().enumerate() {
|
||||
if *operator == b'*' {
|
||||
let mut result = 1;
|
||||
for row in rows.iter() {
|
||||
result *= row[idx];
|
||||
}
|
||||
// println!("row {idx} (*): {result}");
|
||||
sum_of_operations += result;
|
||||
} else {
|
||||
let mut result = 0;
|
||||
for row in rows.iter() {
|
||||
result += row[idx];
|
||||
}
|
||||
// println!("row {idx} (+): {result}");
|
||||
sum_of_operations += result;
|
||||
}
|
||||
}
|
||||
|
||||
println!("sum of operations: {sum_of_operations}");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue