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()) }