Jump to content

Semordnilap: Difference between revisions

m
Line 3,030:
Semordnilap pairs found: 158
</pre>
===A Shortened Version===
<lang Rust>use std::{collections::HashSet, fs};
 
fn reverse(x: &str) -> String {
x.chars().rev().collect::<String>()
}
 
fn main() {
let content = fs::read_to_string("unixdict.txt").expect("No file found!");
let work: HashSet<&str> = content.lines().collect();
 
let mut candidats: Vec<&str> = work.clone().into_iter().collect();
candidats.retain(|&x| work.contains(&reverse(x).as_str()) && x < reverse(x).as_str());
 
println!("Numbers of pairs found: {}", candidats.len());
for ind in 0..5 {
println!("{}, {}", candidats[ind], reverse(candidats[ind]));
}
}</lang>
{{out}}
<pre>Numbers of pairs found: 158
mn, nm
map, pam
saw, was
deep, peed
door, rood</pre>
 
=={{header|Scala}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.