SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     let input = 1234567890;
  3.     let result: Vec<i32> = (0..=(input as f32).log10() as i32)
  4.         .rev()
  5.         .map(|n| input / 10f32.powi(n) as i32 % 10)
  6.         .collect();
  7.     println!("{:?}", result);
  8.    
  9.     let mut result: Vec<i32> = std::iter::repeat(())
  10.         .scan(input, |state, _| {
  11.             let v = *state;
  12.             *state /= 10;
  13.             match v {0=>None, x => Some(x % 10)}
  14.         })
  15.         .collect();
  16.     result.reverse();
  17.     println!("{:?}", result);
  18. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top