How to resolve the algorithm Semordnilap step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Semordnilap step by step in the 11l programming language

Table of Contents

Problem Statement

A semordnilap is a word (or phrase) that spells a different word (or phrase) backward. "Semordnilap" is a word that itself is a semordnilap. Example: lager and regal

This task does not consider semordnilap phrases, only single words. Using only words from this list, report the total number of unique semordnilap pairs, and print 5 examples. Two matching semordnilaps, such as lager and regal, should be counted as one unique pair. (Note that the word "semordnilap" is not in the above dictionary.)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Semordnilap step by step in the 11l programming language

Source code in the 11l programming language

V wordset = Set(File(‘unixdict.txt’).read().split("\n"))
V revlist = wordset.map(word -> reversed(word))
V pairs = Set(zip(wordset, revlist).filter((wrd, rev) -> wrd < rev & rev C :wordset))

print(pairs.len)
print(sorted(Array(pairs), key' p -> (p[0].len, p))[(len)-5..])

  

You may also check:How to resolve the algorithm Brilliant numbers step by step in the Raku programming language
You may also check:How to resolve the algorithm 100 prisoners step by step in the Rust programming language
You may also check:How to resolve the algorithm Mayan numerals step by step in the F# programming language
You may also check:How to resolve the algorithm Mutex step by step in the Julia programming language
You may also check:How to resolve the algorithm De Bruijn sequences step by step in the Phix programming language