tangled
alpha
login
or
join now
nove.dev
/
aoc-2025
1
fork
atom
:)
1
fork
atom
overview
issues
pulls
pipelines
day6 part2
nove.dev
3 months ago
e43f7c5d
b88975d9
+53
-22
3 changed files
expand all
collapse all
unified
split
src
day6.rs
lib.rs
spatial.rs
+35
-15
src/day6.rs
···
1
use itertools::Itertools;
2
0
0
3
pub fn day6_part1(input: &str) -> String {
4
-
let problems = parse(input);
5
-
let answers = problems.iter().map(|(operands, operator)| evaluate(operands, *operator)).collect_vec();
0
0
0
6
dbg!(answers).iter().sum::<u64>().to_string()
7
}
8
9
pub fn day6_part2(input: &str) -> String {
10
-
todo!()
0
0
0
0
0
11
}
12
13
fn evaluate(operands: &[u64], operator: Operator) -> u64 {
···
23
Times,
24
}
25
26
-
fn parse(input: &str) -> Vec<(Vec<u64>, Operator)> {
27
let rows: Vec<Vec<char>> = input.lines().map(|line| line.chars().collect()).collect();
28
let mut problems = vec![];
29
let mut beginning_of_last_problem = 0;
···
43
let mut parsed_problems = vec![];
44
45
for problem in problems {
46
-
let operands = problem[..problem.len() - 1]
47
-
.iter()
48
-
.map(|chars| {
49
-
chars
50
-
.iter()
51
-
.collect::<String>()
52
-
.trim_ascii()
53
-
.parse()
54
-
.unwrap()
55
-
})
56
-
.collect_vec();
0
0
0
0
0
0
0
0
0
0
57
let operator = problem[problem.len() - 1]
58
.iter()
59
.collect::<String>()
···
1
use itertools::Itertools;
2
3
+
use crate::spatial;
4
+
5
pub fn day6_part1(input: &str) -> String {
6
+
let problems = parse(input, false);
7
+
let answers = problems
8
+
.iter()
9
+
.map(|(operands, operator)| evaluate(operands, *operator))
10
+
.collect_vec();
11
dbg!(answers).iter().sum::<u64>().to_string()
12
}
13
14
pub fn day6_part2(input: &str) -> String {
15
+
let problems = parse(input, true);
16
+
let answers = problems
17
+
.iter()
18
+
.map(|(operands, operator)| evaluate(operands, *operator))
19
+
.collect_vec();
20
+
dbg!(answers).iter().sum::<u64>().to_string()
21
}
22
23
fn evaluate(operands: &[u64], operator: Operator) -> u64 {
···
33
Times,
34
}
35
36
+
fn parse(input: &str, cephalopod_style: bool) -> Vec<(Vec<u64>, Operator)> {
37
let rows: Vec<Vec<char>> = input.lines().map(|line| line.chars().collect()).collect();
38
let mut problems = vec![];
39
let mut beginning_of_last_problem = 0;
···
53
let mut parsed_problems = vec![];
54
55
for problem in problems {
56
+
let operands = if !cephalopod_style {
57
+
problem[..problem.len() - 1]
58
+
.iter()
59
+
.map(|chars| {
60
+
chars
61
+
.iter()
62
+
.collect::<String>()
63
+
.trim_ascii()
64
+
.parse()
65
+
.unwrap()
66
+
})
67
+
.collect_vec()
68
+
} else {
69
+
let transposed = spatial::transpose(&problem[..problem.len() - 1]);
70
+
71
+
transposed
72
+
.into_iter()
73
+
.map(|line| line.iter().collect::<String>().trim().parse().unwrap())
74
+
.collect_vec()
75
+
};
76
+
77
let operator = problem[problem.len() - 1]
78
.iter()
79
.collect::<String>()
+7
-7
src/lib.rs
···
132
let result = day6::day6_part1(include_str!("../input/day6.txt"));
133
assert_eq!(result, "4951502530386");
134
}
135
-
// #[test]
136
-
// fn day6_part2_test() {
137
-
// let test_result = day6::day6_part2(include_str!("../input/day6.test.txt"));
138
-
// assert_eq!(test_result, "14");
139
-
// // let result = day6::day6_part2(include_str!("../input/day6.txt"));
140
-
// // assert_eq!(result, "348115621205535");
141
-
// }
142
143
#[test]
144
fn day5_part1_test() {
···
132
let result = day6::day6_part1(include_str!("../input/day6.txt"));
133
assert_eq!(result, "4951502530386");
134
}
135
+
#[test]
136
+
fn day6_part2_test() {
137
+
let test_result = day6::day6_part2(include_str!("../input/day6.test.txt"));
138
+
assert_eq!(test_result, "3263827");
139
+
let result = day6::day6_part2(include_str!("../input/day6.txt"));
140
+
assert_eq!(result, "8486156119946");
141
+
}
142
143
#[test]
144
fn day5_part1_test() {
+11
src/spatial.rs
···
70
71
retval
72
}
0
0
0
0
0
0
0
0
0
0
0
···
70
71
retval
72
}
73
+
74
+
pub fn transpose<T: Copy + Default>(input: &[&[T]]) -> Vec<Vec<T>> {
75
+
let mut output = vec![vec![Default::default(); input.len()]; input[0].len()];
76
+
77
+
for col in 0..input[0].len() {
78
+
for row in 0..input.len() {
79
+
output[col][row] = input[row][col]
80
+
}
81
+
}
82
+
output
83
+
}