SHARE
TWEET

Untitled

a guest Apr 19th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern crate itertools; // 0.8.0
  2.  
  3. use itertools::Itertools; // 0.8.0
  4. use std::char;
  5. use std::u64;
  6.  
  7. fn g(x: u64) -> u64 {
  8.     let s = x.to_string();
  9.     let s = s
  10.         .chars()
  11.         .map(|c| c.to_digit(10).unwrap())
  12.         .group_by(|&k| k)
  13.         .into_iter()
  14.         .fold(String::new(), |mut acc, (k, group)| {
  15.             let n = group.count().to_string();
  16.             let k = char::from_digit(k, 10).unwrap();
  17.             acc.push_str(&n);
  18.             acc.push(k);
  19.             acc
  20.         });
  21.     u64::from_str_radix(&s, 10).unwrap()
  22. }
  23.  
  24. fn main() {
  25.     assert_eq!(221311, g(2231));
  26.     assert_eq!(1411213, g(4222222222223));
  27. }
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