Guest User

Untitled

a guest
Jun 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. fn higher_than_mean_with_thresh(input: [u16; 4]) -> [bool; 4] {
  2.  
  3. println!("\n{:?}", input);
  4. let threshold = 0.2;
  5.  
  6. let mut output = [false; 4];
  7. let average = input.iter().map(|&x| x as f64).fold(0.0, |a, b| a + b) / 4.0;
  8. let mut input = input.iter().enumerate().collect::<Vec<_>>();
  9. input.sort_by_key(|a| a.1);
  10.  
  11. output[input[3].0 as usize] = true;
  12. if *(input[2].1) as f64 > average + threshold {
  13. output[input[2].0 as usize] = true;
  14. }
  15.  
  16. output
  17. }
  18.  
  19. fn main() {
  20. println!("{:?}", higher_than_mean_with_thresh([1,2,3,4]));
  21. println!("{:?}", higher_than_mean_with_thresh([0,9,1,8]));
  22. println!("{:?}", higher_than_mean_with_thresh([0,0,9,0]));
  23. }
Add Comment
Please, Sign In to add comment