Semordnilap: Difference between revisions

m
imported>Rowsety Moid
 
(5 intermediate revisions by 4 users not shown)
Line 3,202:
 
=={{header|Seed7}}==
Note that the Seed7 program downloads unixdict.txt from the net.
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "gethttp.s7i";
 
const func string: reverse (in string: word) is func
result
var string: drow is "";
local
var integer: index is 0;
begin
for index range length(word) downto 1 do
drow &:= word[index];
end for;
end func;
 
const proc: main is func
Line 3,224 ⟶ 3,214:
var integer: count is 0;
begin
wordList := split(lower(getHttp("wwwwiki.puzzlers.org/pub/wordlists/unixdict.txt")), "\n");
for word range wordList do
drow := reverse(word);
Line 3,492 ⟶ 3,482:
4. ah'ha
5. al'la
</pre>
 
=={{header|Uiua}}==
For each word check its reverse is in the array, and that it's greater. This removes palindromes and also keeps only first of each pair.
 
<syntaxhighlight lang="Uiua">
&p &pf "Count: " ⧻.▽≡(×>⇌.⟜∊⇌)⟜¤. ⊜□ ≠@\n. &fras "unixdict.txt"
</syntaxhighlight>
{{out}}
<pre>
Count: 158
{"able" "abut" "ac" "ah" "al" "am" "amos" "and" "ape" "aps" "are"
...
"pot" "pow" "pus" "rat" "raw" "rot" "saw" "suez" "tort" "tv" "way"}
</pre>
 
Line 3,545 ⟶ 3,549:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
var dict = File.read("unixdict.txt").split("\n")
Line 3,657 ⟶ 3,661:
158
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">dim norm$(27000), result$(270, 2)
 
print "Start reading unixdict.txt"
open "i:\unixdict.txt" for reading as #1
 
while not(eof(#1)) // read to end of file
line input #1 in_str$ // get line = word
in_str$ = trim$(in_str$) // we don//t want spaces
if len(in_str$) > 1 then // if length > 1 then reverse$
rev$ = reverse$(in_str$)
if in_str$ <> rev$ then // if in_str is not a palingdrome
count = count + 1 // increase counter
norm$(count) = in_str$ // store in the array
big$ = big$ + rev$ + " " // create big string with reverse$d words
fi
fi
wend
 
close #1
print " ... Done"
print
print "Start looking for semordnilap"
 
for i = 1 to count
for j = 1 to amount // check to avoid the double
if result$(j, 2) = norm$(i) continue
next j
j = instr(big$, " " + norm$(i) + " ")
if j <> 0 then // found one
amount = amount + 1 // increase counter
result$(amount, 1) = norm$(i) // store normal word
result$(amount, 2) = reverse$(norm$(i)) // store reverse$ word
fi
next i
 
print
print "Found", amount, " unique semordnilap pairs"
print
print "Display 5 semordnilap pairs"
print
 
count = 0
for i = 1 to amount
if len(result$(i, 1)) >= 5 then
count = count + 1
print result$(i, 1), chr$(9), result$(i, 2)
if count >= 5 break
fi
next i
end
 
sub reverse$(norm$)
local rev$, i, l
l = len(norm$) - 1
rev$ = norm$
for i = 0 to l
mid$(rev$, l - i, 1) = mid$(norm$, i, 1)
next i
return rev$
end sub</syntaxhighlight>
{{out}}
<pre>
Start reading unixdict.txt
... Done
 
Start looking for semordnilap
 
Found70 unique semordnilap pairs
 
Display 5 semordnilap pairs
 
diesel seidel
dirge ridge
gamma magma
groan organ
latus talus
 
---Program done, press RETURN---</pre>
 
=={{header|zkl}}==
69

edits