Skip to content

Commit caac913

Browse files
committed
feat(06/2025): solve first part
1 parent 7526474 commit caac913

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
| [Day 3: Lobby](src/solutions/year2025/day03.rs) | ⭐⭐ | 0.131 | 0.133 |
1717
| [Day 4: Printing Department](src/solutions/year2025/day04.rs) | ⭐⭐ | 3.615 | 9.998 |
1818
| [Day 5: Cafeteria](src/solutions/year2025/day05.rs) || 0.275 | - |
19-
| [Day 6: Trash Compactor](src/solutions/year2025/day06.rs) | | - | - |
19+
| [Day 6: Trash Compactor](src/solutions/year2025/day06.rs) | | 0.117 | - |
2020

2121
# 2024
2222

src/solutions/year2025/day06.rs

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,86 @@
11
use crate::solutions::Solution;
2+
use itertools::Itertools;
3+
use std::str::FromStr;
24

35
pub struct Day06;
46

57
impl Solution for Day06 {
6-
fn part_one(&self, _input: &str) -> String {
7-
String::from("0")
8+
fn part_one(&self, input: &str) -> String {
9+
let (numbers, operations) = self.parse(input);
10+
let column_count = numbers.first().unwrap().len();
11+
12+
(0..column_count)
13+
.map(|column| {
14+
let operation = operations.get(column).unwrap();
15+
let numbers_in_column = numbers.iter().map(|n_vec| n_vec[column]);
16+
17+
match operation {
18+
Operation::Add => numbers_in_column.sum::<u64>(),
19+
Operation::Multiply => numbers_in_column.product(),
20+
}
21+
})
22+
.sum::<u64>()
23+
.to_string()
824
}
925

1026
fn part_two(&self, _input: &str) -> String {
1127
String::from("0")
1228
}
1329
}
1430

31+
impl Day06 {
32+
fn parse(&self, input: &str) -> (Vec<Vec<u64>>, Vec<Operation>) {
33+
let mut lines = input.lines().collect_vec();
34+
let operations_str = lines.pop().unwrap();
35+
36+
let numbers = lines
37+
.iter()
38+
.map(|line| {
39+
line.split_whitespace()
40+
.map(|x| x.parse::<u64>().unwrap())
41+
.collect_vec()
42+
})
43+
.collect_vec();
44+
45+
let operations = operations_str
46+
.split_whitespace()
47+
.map(|x| x.parse::<Operation>().unwrap())
48+
.collect_vec();
49+
50+
(numbers, operations)
51+
}
52+
}
53+
54+
#[derive(Debug)]
55+
enum Operation {
56+
Add,
57+
Multiply,
58+
}
59+
60+
impl FromStr for Operation {
61+
type Err = ();
62+
63+
fn from_str(s: &str) -> Result<Self, Self::Err> {
64+
match s {
65+
"+" => Ok(Operation::Add),
66+
"*" => Ok(Operation::Multiply),
67+
_ => Err(()),
68+
}
69+
}
70+
}
71+
1572
#[cfg(test)]
1673
mod tests {
1774
use crate::solutions::year2025::day06::Day06;
1875
use crate::solutions::Solution;
1976

20-
const EXAMPLE: &str = r#""#;
77+
const EXAMPLE: &str = r#"123 328 51 64
78+
45 64 387 23
79+
6 98 215 314
80+
* + * + "#;
2181

2282
#[test]
2383
fn part_one_example_test() {
24-
assert_eq!("0", Day06.part_one(EXAMPLE));
84+
assert_eq!("4277556", Day06.part_one(EXAMPLE));
2585
}
2686
}

0 commit comments

Comments
 (0)