Skip to content

Instantly share code, notes, and snippets.

@bylatt
Last active July 11, 2023 04:25
Show Gist options
  • Save bylatt/2bccc1f64bca080ee2e4e785e1830b15 to your computer and use it in GitHub Desktop.
Save bylatt/2bccc1f64bca080ee2e4e785e1830b15 to your computer and use it in GitHub Desktop.
Get longest word from macOS dict file in Rust
use std::fs;
fn main() {
let content =
fs::read_to_string("/usr/share/dict/words").unwrap_or("cannot read file".to_string());
let longest_word =
content.split("\n").fold(
"",
|prev, cur| if cur.len() > prev.len() { cur } else { prev },
);
println!("{longest_word}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment