tangled
alpha
login
or
join now
nove.dev
/
aoc-2025
1
fork
atom
:)
1
fork
atom
overview
issues
pulls
pipelines
questionable code cleanup
nove.dev
3 months ago
49929560
e43f7c5d
+18
-40
2 changed files
expand all
collapse all
unified
split
src
day6.rs
spatial.rs
+14
-31
src/day6.rs
···
44
}
45
problems.push(
46
(0..rows.len())
47
-
.map(|row| &rows[row][beginning_of_last_problem..col])
48
.collect_vec(),
49
);
50
beginning_of_last_problem = col + 1;
51
}
52
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]);
0
0
0
0
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>()
80
-
.trim_ascii()
81
-
.to_owned();
82
-
let operator = match operator.as_str() {
83
"+" => Operator::Plus,
84
"*" => Operator::Times,
85
_ => unreachable!("{operator}"),
86
};
87
-
parsed_problems.push((operands, operator));
88
-
}
0
89
90
-
parsed_problems
91
}
···
44
}
45
problems.push(
46
(0..rows.len())
47
+
.map(|row| rows[row][beginning_of_last_problem..col].to_vec())
48
.collect_vec(),
49
);
50
beginning_of_last_problem = col + 1;
51
}
52
53
+
let parsed_problems = problems.into_iter().map(|problem| {
0
0
54
let operands = if !cephalopod_style {
55
+
problem[..problem.len() - 1].to_vec()
0
0
0
0
0
0
0
0
0
0
56
} else {
57
+
spatial::transpose(&problem[..problem.len() - 1])
58
+
}
59
+
.iter()
60
+
.map(|line| line.iter().collect::<String>().trim().parse().unwrap())
61
+
.collect();
62
63
+
let operator = problem[problem.len() - 1].iter().collect::<String>();
64
+
let operator = match operator.trim() {
0
0
0
0
0
0
0
0
0
0
65
"+" => Operator::Plus,
66
"*" => Operator::Times,
67
_ => unreachable!("{operator}"),
68
};
69
+
70
+
(operands, operator)
71
+
});
72
73
+
parsed_problems.collect()
74
}
+4
-9
src/spatial.rs
···
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
}
···
71
retval
72
}
73
74
+
pub fn transpose<S: AsRef<[T]>, T: Copy>(input: &[S]) -> Vec<Vec<T>> {
75
+
(0..input[0].as_ref().len())
76
+
.map(|col| input.iter().map(|row| row.as_ref()[col]).collect())
77
+
.collect()
0
0
0
0
0
78
}