From d021985d54af172788ff46f17bdefbe47e6dfe7d Mon Sep 17 00:00:00 2001 From: alyx Date: Fri, 1 Dec 2023 00:55:00 -0500 Subject: optimize 2023.1 slightly --- 2023/rs/code/one/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to '2023/rs') diff --git a/2023/rs/code/one/src/main.rs b/2023/rs/code/one/src/main.rs index 1b04f08..638b9a5 100644 --- a/2023/rs/code/one/src/main.rs +++ b/2023/rs/code/one/src/main.rs @@ -23,6 +23,8 @@ fn main() { let calvals = valueified.map(|s| { let mut d1 = 0; let mut d2 = 0; + + let mut indexoff = 0; for i in 0..s.len() { let c = s[i]; if c >= b'0' && c <= b'9' { @@ -32,9 +34,10 @@ fn main() { else { for i2 in 0..NUMS.len() { let num = NUMS[i2]; - if s.len() >= i + num.len() && &s[i..i+num.len()] == num { + if s[i..].starts_with(num) { if d1 == 0 { d1 = i2 as u8 + b'1'; } d2 = i2 as u8 + b'1'; + break; } } } -- cgit v1.2.3-70-g09d2