Semordnilap: Difference between revisions

Content deleted Content added
m added whitespace, added section headers.
m →‎version 2: added/changed comments and whitespace, changed indentations.
Line 1,996:
This REXX version makes use of sparse (stemmed) arrays.
<br><br>The dictionary file wasn't assumed to be in any particular case (upper/lower/mixed).
<br>For instance, &nbsp; '''DNA''' &nbsp; <big> &amp; </big> &nbsp; '''and''' &nbsp; would be considered palindromes.
<br>The UNIXDICT dictionary specified to be used ''is'' all lowercase, however, but the REXX
<br>program assumes that the words may be in any ''case'' &nbsp; (upper, lower, mixed).
Line 2,004:
<br>The palindrome pairs are shown with a comma delimiter in case there're phrases (words with imbedded blanks like Sing Sing).
<br>The (first five) palindrome pairs are shown as they are specified (respective to case) in the dictionary.
<lang rexx>/*REXX program finds palindrome pairs usingin a dictionary (the default is UNIXDICT.TXT). */
#=0 /*#number palindromes (so far).*/
parse arg iFID .; if iFID=='' then iFID='UNIXDICT.TXT' /*useNot defaultspecified? Use default.*/
@.= /*caselessuppercase no-dupedno─duplicated word*/
do while lines(iFID)\==0; _=space(linein(iFID),0); parse upper var/*read _a word from udictionary.*/
ifparse length(_)<2upper |var _ @.u\=='' then iterate /*can't beobtain aan uniqueuppercase palversion.*/
r=reverseif length(u_)<2 | @.u\=='' then iterate /*getcan't thebe reversea of U.unique palindrome*/
if @.r\==''reverse(u) then do; #=#+1 /*foundget palindromethe pair?reverse of the word.*/
if @.r\=='' then do; #=#+1 if #<6 then say @.r',' _ /*onlyfind a palindrome pair ? list first 5 pals*/
end if #<6 then say @.r',' _ /*just [↑]show 1st bump5 count, showpalindromes.*/
@.u=_ end /*define palindromic[↑] pal bump palindrome count.*/
end@.u=_ /*while*/ /*define [↑]a unique read dictionarypalindrome. */
end /*while*/ /* [↑] read the dictionary. */
say
say "There're " # ' unique palindrome pairs in the dictionary file: ' iFID
/*stick a fork in it, we're done. */</lang>
'''output''' &nbsp; when using the default dictionary as the input:
<pre>
ac, ca