SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn sum_slice(v: &[i32]) -> i32 {
  2.     v.iter().sum()
  3. }
  4.  
  5. fn sum_previous(v: &mut [i32]) {
  6.     for (i, val) in v.iter_mut().enumerate() {
  7.         *val = sum_slice(&v[0..i]);
  8.     }
  9. }
  10.  
  11. fn main() {
  12.     let mut v = vec![1,1,1,1,1,1,1];
  13.     sum_previous(&mut v);
  14.     println!("{:?}", v);
  15. }
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