loading...

re: Daily Challenge #225 - Square'n'Sum VIEW POST

FULL DISCUSSION
 

Sum of squares is the default example of the Rayon crate:

use rayon::prelude::*;
fn sum_of_squares(input: &[i32]) -> i32 {
    input.par_iter() // <-- just change that!
         .map(|&i| i * i)
         .sum()
}

(this runs in parallel)

Apparently people here are really into onelinerization.

let sum_of_squares = |nums| nums.iter().map(|&i| i * i).sum();

No parallelism, but at least it's shorter than Python.

code of conduct - report abuse