Last active
July 11, 2023 04:25
-
-
Save bylatt/2bccc1f64bca080ee2e4e785e1830b15 to your computer and use it in GitHub Desktop.
Get longest word from macOS dict file in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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