Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Parallel-calculations/Rust/parallel-calculations.rust
Normal file
29
Task/Parallel-calculations/Rust/parallel-calculations.rust
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
//! This solution uses [rayon](https://github.com/rayon-rs/rayon), a data-parallelism library.
|
||||
//! Since Rust guarantees that a program has no data races, adding parallelism to a sequential
|
||||
//! computation is as easy as importing the rayon traits and calling the `par_iter()` method.
|
||||
|
||||
extern crate rayon;
|
||||
|
||||
extern crate prime_decomposition;
|
||||
|
||||
use rayon::prelude::*;
|
||||
|
||||
/// Returns the largest minimal factor of the numbers in a slice
|
||||
pub fn largest_min_factor(numbers: &[usize]) -> usize {
|
||||
numbers
|
||||
.par_iter()
|
||||
.map(|n| {
|
||||
// `factor` returns a sorted vector, so we just take the first element.
|
||||
prime_decomposition::factor(*n)[0]
|
||||
})
|
||||
.max()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let numbers = &[
|
||||
1_122_725, 1_125_827, 1_122_725, 1_152_800, 1_157_978, 1_099_726,
|
||||
];
|
||||
let max = largest_min_factor(numbers);
|
||||
println!("The largest minimal factor is {}", max);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue