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

Published on 12 May 2024 09:40 PM

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

Source code in the autohotkey programming language

S := [], M := []

FileRead, dict, unixdict.txt
Loop, Parse, dict, `n, `r`n
{
	r := Reverse(A_LoopField)
	if (S[r])
		M.Insert(r " / " A_LoopField)
	else
		S[A_LoopField] := 1
}

Loop, 5
	Out .= "`t" M[A_Index] "`n"

MsgBox, % "5 Examples:`n" Out "`nTotal Pairs:`n`t" M.MaxIndex()

Reverse(s) {
	Loop, Parse, s
		r := A_LoopField . r
	return r
}


  

You may also check:How to resolve the algorithm Multiple distinct objects step by step in the Phix programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the AutoIt programming language
You may also check:How to resolve the algorithm Balanced ternary step by step in the Go programming language
You may also check:How to resolve the algorithm Balanced brackets step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm FASTA format step by step in the Run BASIC programming language