daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest May 17th, 2018 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     let d = [1, 2, 3, 4, 5, 6, 7, 8];
  3.  
  4.     let max = d.iter().zip(d.iter().cycle().skip(3)).zip(d.iter().cycle().skip(3).zip(d.iter()))
  5.         .fold(
  6.             (
  7.                 d.iter().take(3).sum::<i32>(),
  8.                 d.iter().rev().take(5).sum::<i32>(),
  9.                 None
  10.             ),
  11.             | (a, b, result), ((less_a, plus_a), (less_b, plus_b))| {
  12.                 let result = match result {
  13.                     Some(x) => Some(std::cmp::max(x, i32::abs(3 * a + 5 * b))),
  14.                     None => Some(i32::abs(3 * a + 5 * b))
  15.                 };
  16.                 (a - less_a + plus_a , b - less_b + plus_b, result)
  17.             }
  18.         );
  19.     println!("{:?}", max);
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top