Switch to tabs (not spaces).
Stupid default options for NeoVim think it's a good idea to switch my indentation type without asking me.
This commit is contained in:
parent
3f089ad0a4
commit
343a89e89f
54
src/main.rs
54
src/main.rs
@ -20,35 +20,35 @@ use std::env;
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args:Vec<String> = env::args().collect();
|
let args:Vec<String> = env::args().collect();
|
||||||
|
|
||||||
// get the first `n` primes
|
// get the first `n` primes
|
||||||
let n:usize = args[1].parse().unwrap();
|
let n:usize = args[1].parse().unwrap();
|
||||||
let mut primes:VecDeque<u64> = VecDeque::with_capacity(n);
|
let mut primes:VecDeque<u64> = VecDeque::with_capacity(n);
|
||||||
// first prime
|
// first prime
|
||||||
println!("{}", 2);
|
println!("{}", 2);
|
||||||
primes.push_back(2);
|
primes.push_back(2);
|
||||||
|
|
||||||
let mut candidate:u64 = 3;
|
let mut candidate:u64 = 3;
|
||||||
|
|
||||||
while primes.len() < n
|
while primes.len() < n
|
||||||
{
|
{
|
||||||
let mut is_prime = true;
|
let mut is_prime = true;
|
||||||
let limit = (candidate as f64).sqrt() as u64;
|
let limit = (candidate as f64).sqrt() as u64;
|
||||||
for i in primes.iter().take_while(|x| **x <= limit)
|
for i in primes.iter().take_while(|x| **x <= limit)
|
||||||
{
|
{
|
||||||
if candidate % *i == 0
|
if candidate % *i == 0
|
||||||
{
|
{
|
||||||
is_prime = false;
|
is_prime = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_prime
|
if is_prime
|
||||||
{
|
{
|
||||||
println!("{}", candidate);
|
println!("{}", candidate);
|
||||||
primes.push_back(candidate);
|
primes.push_back(candidate);
|
||||||
}
|
}
|
||||||
candidate += 2;
|
candidate += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user