Change e letters to i in words: Difference between revisions

Added Rust solution
(Added C solution)
(Added Rust solution)
Line 1,134:
26. welles => willis
done...
</pre>
 
=={{header|Rust}}==
<lang rust>use std::collections::BTreeSet;
use std::fs::File;
use std::io::{self, BufRead};
 
fn load_dictionary(filename: &str, min_length: usize) -> std::io::Result<BTreeSet<String>> {
let file = File::open(filename)?;
let mut dict = BTreeSet::new();
for line in io::BufReader::new(file).lines() {
let word = line?;
if word.len() >= min_length {
dict.insert(word);
}
}
Ok(dict)
}
 
fn main() {
match load_dictionary("unixdict.txt", 6) {
Ok(dictionary) => {
let mut count = 0;
for word in dictionary.iter().filter(|x| x.contains("e")) {
let word2 = word.replace("e", "i");
if dictionary.contains(&word2) {
count += 1;
println!("{:2}. {:<9} -> {}", count, word, word2);
}
}
}
Err(error) => eprintln!("{}", error),
}
}</lang>
 
{{out}}
<pre>
1. analyses -> analysis
2. atlantes -> atlantis
3. bellow -> billow
4. breton -> briton
5. clench -> clinch
6. convect -> convict
7. crises -> crisis
8. diagnoses -> diagnosis
9. enfant -> infant
10. enquiry -> inquiry
11. frances -> francis
12. galatea -> galatia
13. harden -> hardin
14. heckman -> hickman
15. inequity -> iniquity
16. inflect -> inflict
17. jacobean -> jacobian
18. marten -> martin
19. module -> moduli
20. pegging -> pigging
21. psychoses -> psychosis
22. rabbet -> rabbit
23. sterling -> stirling
24. synopses -> synopsis
25. vector -> victor
26. welles -> willis
</pre>
 
1,777

edits