a-conjecture-of-mine

An exercise on polyglossy: the same problem solved on multiple languages

commit 4db9a614662adf9d05e58ee89562bcf700cbe087
parent b4ff4be394817bc01b2ad9337da8c61446e092b1
Author: Pablo Escobar Gaviria <gark.garcia@protonmail.com>
Date:   Sun,  2 Feb 2020 09:43:48 -0200

Replaced _for loop_ for _while loop_ in the Rust implementation to improve performance.

Since _for loops_ in Rust are just syntatic sugar for successive calls to `Iterator::next`, manually increment the variable in a while loop is a little bit more effient. Performance was reduced by about 1.6330%.

Diffstat:
MRust/main.rs | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Rust/main.rs b/Rust/main.rs
@@ -77,12 +77,16 @@ fn counterexempl_range(
     max: usize
 ) -> bool {
     let mut a = 0usize;
+    let mut b;
 
     while a <= max {
-        for b in a..max {
+        b = 0;
+        while b <= a {
             if (sums_cache[a + b] - sums_cache[a] - sums_cache[b]) % 9 != 0 {
                 return true;
             }
+
+            b += 1;
         }
 
         a += step;