How to resolve the algorithm Semordnilap step by step in the Lasso programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Semordnilap step by step in the Lasso 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 Lasso programming language
Source code in the lasso programming language
local(
words = string(include_url('http://www.puzzlers.org/pub/wordlists/unixdict.txt')) -> split('\n'),
semordnilaps = array,
found_size,
example,
haveexamples = false,
examples = array
)
#words -> removeall('')
with word in #words do {
local(reversed = string(#word) -> reverse&)
if(not(#word == #reversed) and not(#semordnilaps >> #word) and not(#semordnilaps >> #reversed) and #words >> #reversed) => {
#semordnilaps -> insert(#word = #reversed)
}
}
#found_size = #semordnilaps -> size
while(not(#haveexamples)) => {
#example = #semordnilaps -> get(integer_random(#found_size, 1))
not(#examples >> #example -> name) ? #examples -> insert(#example)
#examples -> size >= 5 ? #haveexamples = true
}
'Total found: '
#found_size
'
'
#examples
You may also check:How to resolve the algorithm Empty program step by step in the Pike programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the Maple programming language
You may also check:How to resolve the algorithm Colour pinstripe/Display step by step in the Delphi programming language
You may also check:How to resolve the algorithm Multiple distinct objects step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Random numbers step by step in the HicEst programming language