tangled
alpha
login
or
join now
nove.dev
/
aoc-2025
1
fork
atom
:)
1
fork
atom
overview
issues
pulls
pipelines
day7 part2
nove.dev
3 months ago
b3984d09
ff06bdba
+22
-19
2 changed files
expand all
collapse all
unified
split
src
day7.rs
lib.rs
+15
-12
src/day7.rs
···
1
1
pub fn day7_part1(input: &str) -> String {
2
2
+
emit_tachyon(input).0.to_string()
3
3
+
}
4
4
+
pub fn day7_part2(input: &str) -> String {
5
5
+
emit_tachyon(input).1.to_string()
6
6
+
}
7
7
+
8
8
+
fn emit_tachyon(input: &str) -> (u64, u64) {
2
9
let (start_col, splittermap) = parse(input);
10
10
+
let mut beam_cols = vec![0; splittermap[0].len()];
11
11
+
beam_cols[start_col] = 1;
3
12
let mut splitcount = 0;
4
4
-
let mut beam_cols = vec![false; splittermap[0].len()];
5
5
-
beam_cols[start_col] = true;
6
13
7
14
for splitter_row in splittermap {
8
8
-
let mut next_beam_cols = vec![false; splitter_row.len()];
15
15
+
let mut next_beam_cols = vec![0; splitter_row.len()];
9
16
next_beam_cols[0] = beam_cols[0];
10
17
next_beam_cols[splitter_row.len() - 1] = beam_cols[splitter_row.len() - 1];
11
18
for col in 1..splitter_row.len() - 1 {
12
19
if splitter_row[col] {
13
13
-
if beam_cols[col] {
14
14
-
next_beam_cols[col - 1] = true;
15
15
-
next_beam_cols[col + 1] = true;
20
20
+
next_beam_cols[col - 1] += beam_cols[col];
21
21
+
next_beam_cols[col + 1] += beam_cols[col];
22
22
+
if beam_cols[col] != 0 {
16
23
splitcount += 1;
17
24
}
18
25
} else {
19
19
-
next_beam_cols[col] |= beam_cols[col]
26
26
+
next_beam_cols[col] += beam_cols[col]
20
27
}
21
28
}
22
29
beam_cols = next_beam_cols;
23
30
}
24
24
-
splitcount.to_string()
25
25
-
}
26
26
-
27
27
-
pub fn day7_part2(input: &str) -> String {
28
28
-
todo!()
31
31
+
(splitcount, beam_cols.into_iter().sum())
29
32
}
30
33
31
34
//true: splitter
+7
-7
src/lib.rs
···
133
133
let result = day7::day7_part1(include_str!("../input/day7.txt"));
134
134
assert_eq!(result, "1490");
135
135
}
136
136
-
// #[test]
137
137
-
// fn day7_part2_test() {
138
138
-
// let test_result = day7::day7_part2(include_str!("../input/day7.test.txt"));
139
139
-
// assert_eq!(test_result, "3263827");
140
140
-
// // let result = day7::day7_part2(include_str!("../input/day7.txt"));
141
141
-
// // assert_eq!(result, "8486156119946");
142
142
-
// }
136
136
+
#[test]
137
137
+
fn day7_part2_test() {
138
138
+
let test_result = day7::day7_part2(include_str!("../input/day7.test.txt"));
139
139
+
assert_eq!(test_result, "40");
140
140
+
let result = day7::day7_part2(include_str!("../input/day7.txt"));
141
141
+
assert_eq!(result, "3806264447357");
142
142
+
}
143
143
144
144
#[test]
145
145
fn day6_part1_test() {