daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn is_almost_seq(list: &[i32]) -> bool {
  2.     let mut last = None;
  3.     let mut seq = true;
  4.     for x in list {
  5.         match last {
  6.             None => last = Some(x),
  7.             Some(ref mut last) => {
  8.                 if x <= last {
  9.                     if seq {
  10.                         seq = false;
  11.                     } else {
  12.                         return false
  13.                     }
  14.                 }
  15.                 *last = x
  16.             }
  17.         }
  18.     }
  19.     true
  20. }
  21.  
  22. #[test]
  23. fn is_almost_seq_test() {
  24.     assert!(is_almost_seq(&[1,2,3]));
  25.     assert!(is_almost_seq(&[1,3,3]));
  26.     assert!(is_almost_seq(&[1,2,3,10]));
  27.     assert!(is_almost_seq(&[1,2,10,3]));
  28.     assert!(is_almost_seq(&[1,2,10,3,4,5]));
  29.     assert!(is_almost_seq(&[1,2,10,3,11,12]));
  30.     assert!(is_almost_seq(&[10,1,2,3,4,5]));
  31.     assert!(!is_almost_seq(&[1,2,10,3,11,5]));
  32.     assert!(!is_almost_seq(&[1,1,1]));
  33. }
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