Skip to content

Instantly share code, notes, and snippets.

@mykhailokrainik
Created October 25, 2020 11:45
Show Gist options
  • Save mykhailokrainik/3952eaa12f6c119acc4c6c960b3f4a2d to your computer and use it in GitHub Desktop.
Save mykhailokrainik/3952eaa12f6c119acc4c6c960b3f4a2d to your computer and use it in GitHub Desktop.
#![feature(assoc_char_funcs)]
use std::collections::VecDeque;
use std::iter::FromIterator;
fn main() -> Result<(), failure::Error> {
let a = "Hello World";
dbg!(a
.split(" ")
.fold(String::with_capacity(a.len()), |mut acc, w| {
let mut s: VecDeque<char> = w.chars().collect();
if s.len() > 2 {
s.swap(1, s.len() - 1);
}
if let Some(c) = s.pop_front() {
let v: Vec<char> = format!("{}", c as u32).chars().collect();
v.into_iter().rev().for_each(|ch| s.push_front(ch));
}
acc.push_str(&String::from_iter(s));
acc.push(' ');
acc
}).trim_end());
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment