Semordnilap: Difference between revisions
Content added Content deleted
m (added whitespace, added section headers.) |
m (→version 2: added/changed comments and whitespace, changed indentations.) |
||
Line 1,996: | Line 1,996: | ||
This REXX version makes use of sparse (stemmed) arrays. |
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><br>The dictionary file wasn't assumed to be in any particular case (upper/lower/mixed). |
||
<br>For instance, '''DNA''' & '''and''' would be considered palindromes. |
<br>For instance, '''DNA''' <big> & </big> '''and''' would be considered palindromes. |
||
<br>The UNIXDICT dictionary specified to be used ''is'' all lowercase, however, but the REXX |
<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'' (upper, lower, mixed). |
<br>program assumes that the words may be in any ''case'' (upper, lower, mixed). |
||
Line 2,004: | 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 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. |
<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 |
<lang rexx>/*REXX program finds palindrome pairs in a dictionary (the default is UNIXDICT.TXT). */ |
||
#=0 /* |
#=0 /*number palindromes (so far).*/ |
||
parse arg iFID .; if iFID=='' then iFID='UNIXDICT.TXT' /* |
parse arg iFID .; if iFID=='' then iFID='UNIXDICT.TXT' /*Not specified? Use default.*/ |
||
@.= /* |
@.= /*uppercase no─duplicated word*/ |
||
do while lines(iFID)\==0; _=space(linein(iFID),0) |
do while lines(iFID)\==0; _=space(linein(iFID),0) /*read a word from dictionary.*/ |
||
parse upper var _ u /*obtain an uppercase version.*/ |
|||
if length(_)<2 | @.u\=='' then iterate /*can't be a unique palindrome*/ |
|||
r=reverse(u) /*get the reverse of the word.*/ |
|||
if @.r\=='' then do; #=#+1 /*find a palindrome pair ? */ |
|||
if #<6 then say @.r',' _ /*just show 1st 5 palindromes.*/ |
|||
end /* [↑] bump palindrome count.*/ |
|||
@.u=_ /*define a unique palindrome. */ |
|||
end /*while*/ /* [↑] read the dictionary. */ |
|||
say |
say |
||
say "There're" # 'unique palindrome pairs in the dictionary file: ' iFID |
say "There're " # ' unique palindrome pairs in the dictionary file: ' iFID |
||
/*stick a fork in it, we're done.*/</lang> |
/*stick a fork in it, we're done. */</lang> |
||
'''output''' when using the default dictionary as the input: |
'''output''' when using the default dictionary as the input: |
||
<pre> |
<pre> |
||
ac, ca |
ac, ca |