Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn higher_than_mean_with_thresh(input: [u16; 4]) -> [bool; 4] {
- println!("\n{:?}", input);
- let threshold = 0.2;
- let mut output = [false; 4];
- let average = input.iter().map(|&x| x as f64).fold(0.0, |a, b| a + b) / 4.0;
- let mut input = input.iter().enumerate().collect::<Vec<_>>();
- input.sort_by_key(|a| a.1);
- output[input[3].0 as usize] = true;
- if *(input[2].1) as f64 > average + threshold {
- output[input[2].0 as usize] = true;
- }
- output
- }
- fn main() {
- println!("{:?}", higher_than_mean_with_thresh([1,2,3,4]));
- println!("{:?}", higher_than_mean_with_thresh([0,9,1,8]));
- println!("{:?}", higher_than_mean_with_thresh([0,0,9,0]));
- }
Add Comment
Please, Sign In to add comment