How to resolve the algorithm Semordnilap step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Semordnilap step by step in the J 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 J programming language

Source code in the j programming language

   isSemordnilap=: |.&.> (~: *. e.) ]
   unixdict=: <;._2 freads 'unixdict.txt'
   #semordnilaps=: ~. /:~"1 (,. |.&.>) (#~ isSemordnilap) unixdict
158


   (5?.158) { semordnilaps
┌────┬────┐
│kay │yak │
├────┼────┤
│nat │tan │
├────┼────┤
│avis│siva│
├────┼────┤
│flow│wolf│
├────┼────┤
│caw │wac │
└────┴────┘


  

You may also check:How to resolve the algorithm Polynomial regression step by step in the Raku programming language
You may also check:How to resolve the algorithm Forward difference step by step in the Clojure programming language
You may also check:How to resolve the algorithm Egyptian division step by step in the F# programming language
You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the Python programming language
You may also check:How to resolve the algorithm Order disjoint list items step by step in the REXX programming language