From c8e1f5841dabc994caed6fefd94cdcd4962986f5 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Tue, 27 Aug 2024 00:26:14 -0500 Subject: [PATCH] Optimize p37 --- rust/src/p0037.rs | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/rust/src/p0037.rs b/rust/src/p0037.rs index 3a0f6105..de6cb40b 100644 --- a/rust/src/p0037.rs +++ b/rust/src/p0037.rs @@ -25,31 +25,25 @@ pub fn p0037() -> Answer { if count == 11 { break; } - else if p < 10 { + if p < 10 { continue; } - else { - let mut left = p; - let mut right = p; - while is_prime(right) { - right /= 10; - } - if right != 0 { - continue; - } - while is_prime(left) { - let mut x = 10; - while x < left { - x *= 10; - } - left %= x / 10; - } - if left != 0 { - continue; - } - answer += p; - count += 1; + let mut left = p; + let mut right = p; + while is_prime(right) { + right /= 10; } + if right != 0 { + continue; + } + while is_prime(left) { + left %= 10u64.pow(left.ilog10()); + } + if left != 0 { + continue; + } + answer += p; + count += 1; } return Answer::Int(answer.into()); }