Skip to content

Commit 552025a

Browse files
committed
Revert "Use u128 to store data"
This reverts commit 85961a2.
1 parent 85961a2 commit 552025a

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/day17.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use aoc_runner_derive::aoc;
1212
// 5 5: out out b
1313
// 3 0: jnz a!=0 -> 0
1414

15-
#[repr(C, align(16))]
16-
struct Allign([u8; 17]);
17-
18-
static mut RESULT: Allign = Allign([0; 17]);
15+
static mut RESULT: [u8; 128] = [0; 128];
1916

2017
#[aoc(day17, part1)]
2118
pub fn part1(s: &str) -> &'static str {
@@ -45,31 +42,25 @@ pub fn part1(s: &str) -> &'static str {
4542
} as u64;
4643

4744
let result_ptr = (&raw mut RESULT).cast::<u8>();
48-
let out_ptr = result_ptr;
45+
let mut out_ptr = result_ptr;
46+
let result_ptr = result_ptr.cast_const();
4947

50-
let mut res = 0u128;
51-
std::hint::assert_unchecked(a > 8);
52-
while a > 8 {
48+
std::hint::assert_unchecked(a != 0);
49+
while a != 0 {
5350
let b = a % 8;
5451
let b = b ^ x;
5552
let c = a >> b;
5653
let b = b ^ y ^ c;
5754

58-
res = res >> 16;
59-
res |= (((b % 8) as u8 + b'0') as u128) << 112;
60-
res |= (b',' as u128) << 120;
55+
out_ptr.write((b % 8) as u8 + b'0');
56+
out_ptr.offset(1).write(b',');
57+
out_ptr = out_ptr.offset(2);
6158
a = a / 8;
6259
}
63-
let b = a % 8;
64-
let b = b ^ x;
65-
let c = a >> b;
66-
let b = b ^ y ^ c;
67-
let b = (b % 8) as u8 + b'0';
6860

69-
out_ptr.cast::<u128>().write(res);
70-
out_ptr.offset(16).write(b);
61+
let out_len = out_ptr.offset_from(result_ptr);
7162

72-
std::str::from_utf8_unchecked(&(*&raw const RESULT).0)
63+
str::from_utf8_unchecked((*&raw const RESULT).get_unchecked(..(out_len - 1) as usize))
7364
}
7465
}
7566

0 commit comments

Comments
 (0)