Remove summation loop

master
Trivernis 5 years ago
parent 738a69b17f
commit 573f00e673

@ -15,23 +15,21 @@ fn main() {
}); });
} }
let time_start = Instant::now(); let time_start = Instant::now();
let mut primes: Vec<u64> = vec![]; let mut prime_sum: u128 = 2;
primes.push(2);
// receives all prime numbers via the channel receiver. // receives all prime numbers via the channel receiver.
// The received prime numbers are stored in a vector // The received prime numbers are stored in a vector
loop { loop {
let result = rx.recv_timeout(Duration::from_millis(10)); let result = rx.recv_timeout(Duration::from_millis(1));
match result { match result {
Err(_) => break, Err(e) => {
println!("{}", e);
break
},
Ok(prime) => { 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!("Prime Sum: {}", prime_sum);
println!("Solution took: {} ms", time_start.elapsed().as_millis()) println!("Solution took: {} ms", time_start.elapsed().as_millis())
} }

Loading…
Cancel
Save