summaryrefslogtreecommitdiffstats
path: root/2023
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2023-12-01 00:55:00 -0500
committeralyx <alyx@aleteoryx.me>2023-12-01 00:55:00 -0500
commitd021985d54af172788ff46f17bdefbe47e6dfe7d (patch)
treef8d0495712fa34d00201fc3633f7c84801294de3 /2023
parenteb2dabb284f754277ab72aa418ef778646f91dcd (diff)
downloadadventofcode-d021985d54af172788ff46f17bdefbe47e6dfe7d.tar.gz
adventofcode-d021985d54af172788ff46f17bdefbe47e6dfe7d.tar.bz2
adventofcode-d021985d54af172788ff46f17bdefbe47e6dfe7d.zip
optimize 2023.1 slightly
Diffstat (limited to '2023')
-rw-r--r--2023/rs/code/one/src/main.rs5
1 files changed, 4 insertions, 1 deletions
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;
}
}
}