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
pub fn day7_part1(input: &str) -> String {
0
0
0
0
0
0
0
2
let (start_col, splittermap) = parse(input);
0
0
3
let mut splitcount = 0;
4
-
let mut beam_cols = vec![false; splittermap[0].len()];
5
-
beam_cols[start_col] = true;
6
7
for splitter_row in splittermap {
8
-
let mut next_beam_cols = vec![false; splitter_row.len()];
9
next_beam_cols[0] = beam_cols[0];
10
next_beam_cols[splitter_row.len() - 1] = beam_cols[splitter_row.len() - 1];
11
for col in 1..splitter_row.len() - 1 {
12
if splitter_row[col] {
13
-
if beam_cols[col] {
14
-
next_beam_cols[col - 1] = true;
15
-
next_beam_cols[col + 1] = true;
16
splitcount += 1;
17
}
18
} else {
19
-
next_beam_cols[col] |= beam_cols[col]
20
}
21
}
22
beam_cols = next_beam_cols;
23
}
24
-
splitcount.to_string()
25
-
}
26
-
27
-
pub fn day7_part2(input: &str) -> String {
28
-
todo!()
29
}
30
31
//true: splitter
···
1
pub fn day7_part1(input: &str) -> String {
2
+
emit_tachyon(input).0.to_string()
3
+
}
4
+
pub fn day7_part2(input: &str) -> String {
5
+
emit_tachyon(input).1.to_string()
6
+
}
7
+
8
+
fn emit_tachyon(input: &str) -> (u64, u64) {
9
let (start_col, splittermap) = parse(input);
10
+
let mut beam_cols = vec![0; splittermap[0].len()];
11
+
beam_cols[start_col] = 1;
12
let mut splitcount = 0;
0
0
13
14
for splitter_row in splittermap {
15
+
let mut next_beam_cols = vec![0; splitter_row.len()];
16
next_beam_cols[0] = beam_cols[0];
17
next_beam_cols[splitter_row.len() - 1] = beam_cols[splitter_row.len() - 1];
18
for col in 1..splitter_row.len() - 1 {
19
if splitter_row[col] {
20
+
next_beam_cols[col - 1] += beam_cols[col];
21
+
next_beam_cols[col + 1] += beam_cols[col];
22
+
if beam_cols[col] != 0 {
23
splitcount += 1;
24
}
25
} else {
26
+
next_beam_cols[col] += beam_cols[col]
27
}
28
}
29
beam_cols = next_beam_cols;
30
}
31
+
(splitcount, beam_cols.into_iter().sum())
0
0
0
0
32
}
33
34
//true: splitter
+7
-7
src/lib.rs
···
133
let result = day7::day7_part1(include_str!("../input/day7.txt"));
134
assert_eq!(result, "1490");
135
}
136
-
// #[test]
137
-
// fn day7_part2_test() {
138
-
// let test_result = day7::day7_part2(include_str!("../input/day7.test.txt"));
139
-
// assert_eq!(test_result, "3263827");
140
-
// // let result = day7::day7_part2(include_str!("../input/day7.txt"));
141
-
// // assert_eq!(result, "8486156119946");
142
-
// }
143
144
#[test]
145
fn day6_part1_test() {
···
133
let result = day7::day7_part1(include_str!("../input/day7.txt"));
134
assert_eq!(result, "1490");
135
}
136
+
#[test]
137
+
fn day7_part2_test() {
138
+
let test_result = day7::day7_part2(include_str!("../input/day7.test.txt"));
139
+
assert_eq!(test_result, "40");
140
+
let result = day7::day7_part2(include_str!("../input/day7.txt"));
141
+
assert_eq!(result, "3806264447357");
142
+
}
143
144
#[test]
145
fn day6_part1_test() {