Skip to content

Commit a44b026

Browse files
committed
Update benchmarks and fix lints
1 parent 1e884c5 commit a44b026

File tree

3 files changed

+57
-56
lines changed

3 files changed

+57
-56
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
8787
| 6 | [Trash Compactor](https://adventofcode.com/2025/day/6) | [Source](src/year2025/day06.rs) | 20 |
8888
| 7 | [Laboratories](https://adventofcode.com/2025/day/7) | [Source](src/year2025/day07.rs) | 5 |
8989
| 8 | [Playground](https://adventofcode.com/2025/day/8) | [Source](src/year2025/day08.rs) | 527 |
90-
| 9 | [Movie Theater](https://adventofcode.com/2025/day/9) | [Source](src/year2025/day09.rs) | 668 |
90+
| 9 | [Movie Theater](https://adventofcode.com/2025/day/9) | [Source](src/year2025/day09.rs) | 128 |
9191
| 10 | [Factory](https://adventofcode.com/2025/day/10) | [Source](src/year2025/day10.rs) | 296 |
9292
| 11 | [Reactor](https://adventofcode.com/2025/day/11) | [Source](src/year2025/day11.rs) | 75 |
9393
| 12 | [Christmas Tree Farm](https://adventofcode.com/2025/day/12) | [Source](src/year2025/day12.rs) | 25 |

docs/pie-2025.svg

Lines changed: 19 additions & 19 deletions
Loading

src/year2025/day09.rs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1+
//! # Movie Theater
12
use crate::util::iter::*;
23
use crate::util::parse::*;
34

45
type Tile = [u64; 2];
56

7+
struct Candidate {
8+
x: u64,
9+
y: u64,
10+
interval: Interval,
11+
}
12+
13+
/// The set { x in u64 | l <= x <= r }.
14+
#[derive(Clone, Copy)]
15+
struct Interval {
16+
l: u64,
17+
r: u64,
18+
}
19+
20+
impl Interval {
21+
fn new(l: u64, r: u64) -> Self {
22+
debug_assert!(l <= r);
23+
24+
Interval { l, r }
25+
}
26+
27+
fn intersects(self, other: Self) -> bool {
28+
other.l <= self.r && self.l <= other.r
29+
}
30+
31+
fn intersection(self, other: Self) -> Self {
32+
debug_assert!(self.intersects(other));
33+
34+
Interval::new(self.l.max(other.l), self.r.min(other.r))
35+
}
36+
37+
fn contains(self, x: u64) -> bool {
38+
self.l <= x && x <= self.r
39+
}
40+
}
41+
642
pub fn parse(input: &str) -> Vec<Tile> {
743
input.iter_unsigned::<u64>().chunk::<2>().collect()
844
}
@@ -33,12 +69,6 @@ pub fn part2(tiles: &[Tile]) -> u64 {
3369

3470
// Each red tile (`x`, `y`) becomes a candidate for being a top corner of the largest area, and during the
3571
// scan the `interval` containing the maximum possible width is updated:
36-
struct Candidate {
37-
x: u64,
38-
y: u64,
39-
interval: Interval,
40-
}
41-
4272
let mut candidates: Vec<Candidate> = Vec::with_capacity(512);
4373

4474
// Maintain an ordered list of descending edges, i.e. [begin_interval_0, end_interval_0, begin_interval_1, end_interval_1, ...]:
@@ -74,7 +104,7 @@ pub fn part2(tiles: &[Tile]) -> u64 {
74104
);
75105

76106
// Check the rectangles this red tile could be a bottom tile for, with the current candidates:
77-
for candidate in candidates.iter() {
107+
for candidate in &candidates {
78108
for x in [x0, x1] {
79109
if candidate.interval.contains(x) {
80110
largest_area = largest_area
@@ -109,35 +139,6 @@ pub fn part2(tiles: &[Tile]) -> u64 {
109139
largest_area
110140
}
111141

112-
/// The set { x in u64 | l <= x <= r }.
113-
#[derive(Clone, Copy)]
114-
struct Interval {
115-
l: u64,
116-
r: u64,
117-
}
118-
119-
impl Interval {
120-
fn new(l: u64, r: u64) -> Self {
121-
debug_assert!(l <= r);
122-
123-
Interval { l, r }
124-
}
125-
126-
fn intersects(self, other: Self) -> bool {
127-
other.l <= self.r && self.l <= other.r
128-
}
129-
130-
fn intersection(self, other: Self) -> Self {
131-
debug_assert!(self.intersects(other));
132-
133-
Interval::new(self.l.max(other.l), self.r.min(other.r))
134-
}
135-
136-
fn contains(self, x: u64) -> bool {
137-
self.l <= x && x <= self.r
138-
}
139-
}
140-
141142
// Adds `value` if it isn't in `ordered_list`, removes it if it is, maintaining the order.
142143
fn toggle_value_membership_in_ordered_list(ordered_list: &mut Vec<u64>, value: u64) {
143144
let mut i = 0;

0 commit comments

Comments
 (0)