Skip to content

Commit 48de02d

Browse files
committed
Have a max of 13 items part 2
1 parent e3ae9be commit 48de02d

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/day23.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ use aoc_runner_derive::aoc;
55
const MAX: usize = 26 * 26;
66

77
const T_START: u16 = (b't' - b'a') as u16 * 26;
8-
const T_END: u16 = T_START + 26;
98

109
const T_START_REM: u16 = (-(T_START as i16)).rem_euclid(MAX as i16) as u16;
1110

11+
const MAX_C: usize = 13;
12+
1213
#[aoc(day23, part1)]
1314
pub fn part1(s: &str) -> u64 {
1415
let s = s.as_bytes();
1516

16-
let mut connections = [const { heapless::Vec::<u16, 13>::new() }; MAX];
17+
let mut connections = [const { heapless::Vec::<u16, MAX_C>::new() }; MAX];
1718
unsafe {
1819
let mut i = 0;
1920
while i < s.len() {
@@ -64,7 +65,7 @@ pub fn part1(s: &str) -> u64 {
6465
}
6566
}
6667

67-
static mut SCRATCH: [u8; 16 * 3] = [0; 16 * 3];
68+
static mut SCRATCH: [u8; MAX_C * 3] = [0; MAX_C * 3];
6869

6970
#[aoc(day23, part2)]
7071
pub fn part2(s: &str) -> &'static str {
@@ -117,10 +118,10 @@ pub fn part2(s: &str) -> &'static str {
117118
vertecies[i].1 = max_degree as u16;
118119
}
119120

120-
let mut cs = [const { heapless::Vec::<u16, 16>::new() }; 16];
121+
let mut cs = [const { heapless::Vec::<u16, MAX_C>::new() }; MAX_C];
121122

122-
let mut q = heapless::Vec::<u16, 16>::new();
123-
let mut q_max = heapless::Vec::<u16, 16>::new();
123+
let mut q = heapless::Vec::<u16, MAX_C>::new();
124+
let mut q_max = heapless::Vec::<u16, MAX_C>::new();
124125

125126
expand(vertecies, &g, &mut q, &mut q_max, &mut cs);
126127

@@ -143,16 +144,16 @@ pub fn part2(s: &str) -> &'static str {
143144
fn expand(
144145
mut r: &mut [(u16, u16)],
145146
g: &[[bool; MAX]; MAX],
146-
q: &mut heapless::Vec<u16, 16>,
147-
q_max: &mut heapless::Vec<u16, 16>,
148-
cs: &mut [heapless::Vec<u16, 16>; 16],
147+
q: &mut heapless::Vec<u16, MAX_C>,
148+
q_max: &mut heapless::Vec<u16, MAX_C>,
149+
cs: &mut [heapless::Vec<u16, MAX_C>; MAX_C],
149150
) {
150151
while let Some(((p, color), rest)) = r.split_last_mut() {
151152
let p = *p as usize;
152153
if q.len() + *color as usize + 1 > q_max.len() {
153154
q.push(p as u16).unwrap();
154155

155-
let mut new_r = heapless::Vec::<(u16, u16), 16>::new();
156+
let mut new_r = heapless::Vec::<(u16, u16), MAX_C>::new();
156157
for (i, _) in rest.iter() {
157158
if g[p][*i as usize] {
158159
new_r.push((*i, 0)).unwrap();
@@ -176,7 +177,7 @@ fn expand(
176177
fn number_sort(
177178
r: &mut [(u16, u16)],
178179
g: &[[bool; MAX]; MAX],
179-
cs: &mut [heapless::Vec<u16, 16>; 16],
180+
cs: &mut [heapless::Vec<u16, MAX_C>; MAX_C],
180181
) {
181182
let mut maxno = 0;
182183
cs[0].clear();

0 commit comments

Comments
 (0)