Probably not the most elegant way... I really need more practice with Rust :D
fn main() { let blob = "..."; let mut result = blob .chars() .fold(vec![(None, 0); 27], |mut counter, c| { if c == '_' { if counter[26].0.is_none() { counter[26].0 = Some('_'); } counter[26].1 += 1; } else { let pos = (c as u8 - 'a' as u8) as usize; if counter[pos].0.is_none() { counter[pos].0 = Some(c); } counter[pos].1 += 1; } counter }) ; result.sort_by(|a,b| b.1.cmp(&a.1)); let result = result .iter() .fold(String::new(), |mut s, c| { s.push(c.0.unwrap_or(' ')); s }) ; let result: Vec<&str> = result .split('_') .collect() ; println!("{}", result[0]); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Probably not the most elegant way... I really need more practice with Rust :D