Skip to content

Commit 63a0c80

Browse files
committed
Document Day 13
1 parent f39d42c commit 63a0c80

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/year2023/day13.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//! # Point of Incidence
2+
//!
3+
//! We store each row of a grid as a binary number. For example `#.##..##.` becomes `101100110`.
4+
//! Then to count smudges we bitwise XOR the respective rows together and count one bits
5+
//! using the [`count_ones`] function.
6+
//!
7+
//! For example:
8+
//! ```none
9+
//! ..##..### 001100111 ^ 000100111 = 00100000 => 1
10+
//! v#####.##.v => 111110110 ^ 111110110 = 00000000 => 0
11+
//! ^#####.##.^
12+
//! ...#..###
13+
//! ````
14+
//!
15+
//! To handle columns we transpose the grid then convert into integers the same way. For part one
16+
//! we look for a reflection axis with 0 smudges and for part two 1 smudge, allowing the same
17+
//! code to be reused.
18+
//!
19+
//! [`count_ones`]: u32::count_ones
120
use crate::util::grid::*;
221
use crate::util::point::*;
322

@@ -65,6 +84,7 @@ fn reflect_axis(axis: &[u32], target: u32) -> Option<usize> {
6584
for i in 1..size {
6685
let mut smudges = 0;
6786

87+
// Only consider rows/columns within the boundary of the grid.
6888
for j in 0..i.min(size - i) {
6989
smudges += (axis[i - j - 1] ^ axis[i + j]).count_ones();
7090
}

0 commit comments

Comments
 (0)