From 573f00e673df1b16f3b759f32ee7ce8b9389085b Mon Sep 17 00:00:00 2001 From: Trivernis Date: Thu, 13 Feb 2020 09:59:22 +0100 Subject: [PATCH] Remove summation loop --- src/main.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index f195e2a..a6e12f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,23 +15,21 @@ fn main() { }); } let time_start = Instant::now(); - let mut primes: Vec = vec![]; - primes.push(2); + let mut prime_sum: u128 = 2; // receives all prime numbers via the channel receiver. // The received prime numbers are stored in a vector loop { - let result = rx.recv_timeout(Duration::from_millis(10)); + let result = rx.recv_timeout(Duration::from_millis(1)); match result { - Err(_) => break, + Err(e) => { + println!("{}", e); + break + }, Ok(prime) => { - primes.push(prime); + prime_sum += prime as u128; } } } - let mut prime_sum: u128 = 0; - for prime in primes { - prime_sum += prime as u128; - } println!("Prime Sum: {}", prime_sum); println!("Solution took: {} ms", time_start.elapsed().as_millis()) }