From 267b9e8c3d64f20d1008e71591fb3969bc1e0bcb Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 2 Dec 2023 20:48:30 +0100 Subject: [PATCH] faster --- 2023/day1/src/no_lines.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/2023/day1/src/no_lines.rs b/2023/day1/src/no_lines.rs index 65e5fdb..3ce8de7 100644 --- a/2023/day1/src/no_lines.rs +++ b/2023/day1/src/no_lines.rs @@ -48,16 +48,17 @@ pub unsafe fn part2(input: &str) { // like: u64::from_be_bytes([0, 0, 0, b't', b'h', b'g', b'i', b'e']) u64::from_be_bytes(bytes) } + + let mut acc = 0; + macro_rules! check { ($const:ident $len:ident == $str:expr => $value:expr) => { const $const: u64 = gorble($str); - digits[line_idx] |= (if $len == $const { $value } else { 0 }); + acc |= (if $len == $const { $value } else { 0 }); }; } - - assert!(line_idx < digits.len()); - digits[line_idx] |= if one >= b'0' && one <= b'9' { one } else { 0 }; + acc |= if one >= b'0' && one <= b'9' { one } else { 0 }; check!(EIGHT five == b"eight" => b'8'); check!(SEVEN five == b"seven" => b'7'); @@ -71,6 +72,8 @@ pub unsafe fn part2(input: &str) { check!(TWO three == b"two" => b'2'); check!(ONE three == b"one" => b'1'); + digits[line_idx] = acc; + byte_idx += 1; line_idx += 1; }