Skip to content

Commit 281dcc7

Browse files
committed
Prob slow
1 parent 4e57b13 commit 281dcc7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/day24.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use aoc_runner_derive::aoc;
55
#[aoc(day24, part1)]
66
pub fn part1(s: &str) -> u64 {
77
let s = s.as_bytes();
8+
part1_inner(s);
9+
part1_inner(s);
10+
part1_inner(s);
811
part1_inner(s)
912

1013
// println!("digraph G {{");
@@ -94,20 +97,27 @@ impl Gate {
9497
if self.out_1 == 0 {
9598
self.out_1 = out;
9699
} else {
97-
debug_assert!(self.out_2 == 0);
100+
// debug_assert!(self.out_2 == 0);
98101
self.out_2 = out;
99102
}
100103
}
101104
}
102105

103-
pub fn part1_inner(s: &[u8]) -> u64 {
104-
let mut gates = [Gate {
106+
#[inline(always)]
107+
fn part1_inner(s: &[u8]) -> u64 {
108+
static mut GATES: [Gate; 26 * 26 * 26 + 46] = [Gate {
105109
inp_1: false,
106110
out_1: 0,
107111
out_2: 0,
108112
state: State::Empty,
109113
}; 26 * 26 * 26 + 46];
110114

115+
let gates = unsafe { &mut *(&raw mut GATES) };
116+
for g in gates.iter_mut() {
117+
g.out_1 = 0;
118+
g.state = State::Empty;
119+
}
120+
111121
let mut stack = heapless::Vec::<(u16, bool), 2048>::new();
112122

113123
let mut i = CSTART;
@@ -227,7 +237,8 @@ pub fn part2(s: &str) -> &'static str {
227237

228238
const ZSTART: u16 = 26 * 26 * 26;
229239

230-
pub fn part2_inner(s: &[u8]) -> &'static str {
240+
#[inline(always)]
241+
fn part2_inner(s: &[u8]) -> &'static str {
231242
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
232243
enum State {
233244
Or,

0 commit comments

Comments
 (0)