Find words which contains more than 3 e vowels: Difference between revisions

From Rosetta Code
Content added Content deleted
(strengthened testing for requirements.)
m (→‎{{header|REXX}}: changed some comments.)
Line 25: Line 25:
say copies('─', 30) # "words in the dictionary file: " iFID
say copies('─', 30) # "words in the dictionary file: " iFID
finds= 0 /*count of the "eeee" words found. */
finds= 0 /*count of the "eeee" words found. */
vowels= 'aeiou'; /*obtain the list of the other vowels. */
vowels= 'aeiou' /*obtain the list of all the vowels. */
upper vowels /*uppercase all the other vowels. */
upper vowels /*uppercase all the other vowels. */
vowels= space( translate( vowels, , chrU), 0) /*elide the one particular vowel. */
vowels= space( translate( vowels, , chrU), 0) /*elide the one vowel we're looking for*/


do j=1 for #; $= @.j /*process all the words that were found*/
do j=1 for #; $= @.j /*process all the words that were found*/
upper $ /*uppercase it for caseless finds. */
upper $ /*uppercase it for caseless finds. */
if pos(chrU, $)==0 then iterate /*At least 1 vowel found? No, then skip*/
if verify(vowels, $, 'M')>0 then iterate /*Does it contain other vowels? Skip it*/
if verify(vowels, $, 'M')>0 then iterate
if countstr(chrU, $) < many then iterate /*Does it have enough of 'e's? " "*/
if countstr(chrU, $) < many then iterate /*Have enough vowels? " " " */
finds= finds + 1 /*bump count of only "e" vowels found. */
finds= finds + 1 /*bump the count of "ABC" words found. */
say right(left(@.j, 30), 40) /*indent original word for readability.*/
say right(left(@.j, 30), 40) /*indent original word for readability.*/
end /*j*/
end /*j*/

Revision as of 07:08, 9 February 2021

Find words which contains more than 3 e vowels is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

Use the dictionary   unixdict.txt

Find words which contains more than three   e   vowels   and   contains only   e   vowels.

REXX

This REXX version doesn't care what order the words in the dictionary are in,   nor does it care what
case  (lower/upper/mixed)  the words are in,   the search for the words and vowels is   caseless.

It also allows the minimum number of vowels to be specified on the command line (CL) as well as the dictionary file identifier. <lang rexx>/*REXX pgm finds words (within an identified dict.) which contain more than three "e"s.*/ parse arg char many iFID . /*obtain optional arguments from the CL*/ if char== | char=="," then char= 'e' /*Not specified? Then use the default.*/ if many== | many=="," then many= 4 /* " " " " " " */ if iFID== | iFID=="," then iFID='unixdict.txt' /* " " " " " " */ chrU= char; upper chrU /*obtain an uppercase version of char.*/

          do #=1  while lines(iFID)\==0         /*read each word in the file  (word=X).*/
          x= strip( linein( iFID) )             /*pick off a word from the input line. */
          @.#= x                                /*save:  the original case of the word.*/
          end   /*#*/                           /* [↑]   semaphore name is uppercased. */
  1. = # - 1 /*adjust word count because of DO loop.*/

say copies('─', 30) # "words in the dictionary file: " iFID finds= 0 /*count of the "eeee" words found. */ vowels= 'aeiou' /*obtain the list of all the vowels. */ upper vowels /*uppercase all the other vowels. */ vowels= space( translate( vowels, , chrU), 0) /*elide the one vowel we're looking for*/

    do j=1  for #;      $= @.j                  /*process all the words that were found*/
    upper $                                     /*uppercase it for caseless finds.     */
    if verify(vowels, $, 'M')>0  then iterate   /*Does it contain other vowels? Skip it*/
    if countstr(chrU, $) < many  then iterate   /*Does it have enough of  'e's?   "   "*/
    finds= finds + 1                            /*bump count of only "e" vowels found. */
    say right(left(@.j, 30), 40)                /*indent original word for readability.*/
    end        /*j*/
                                                /*stick a fork in it,  we're all done. */

say copies('─', 30) finds ' "e" words found using the characters: ' many "'e'"</lang>

output   when using the default inputs:
────────────────────────────── 25104 words in the dictionary file:  unixdict.txt
          belvedere
          dereference
          elsewhere
          erlenmeyer
          evergreen
          everywhere
          exegete
          freewheel
          nevertheless
          persevere
          preference
          referee
          seventeen
          seventeenth
          telemeter
          tennessee
────────────────────────────── 16  "e" words found using the characters:  4 'e'

Ring

<lang ring> load "stdlib.ring"

cStr = read("unixdict.txt") wordList = str2list(cStr) char = list(9) nextwords = [] nr = 0 num = 0

see "working..." + nl

ln = len(wordList) for n = ln to 1 step -1

   if len(wordList[n]) < 6
      del(wordList,n)
   ok

next

see "Words are:" + nl

for n = 1 to len(wordList)

   num = 0
   flag = 1
   for m = 1 to len(wordList[n])
       if isvowel(wordList[n][m])
          if wordList[n][m] != "e"
             flag = 0
             exit
          else
             num = num + 1
          ok
       ok
   next
   if flag = 1 and num > 3
      nr = nr + 1
      see "" + nr + ". " + wordList[n] + nl
   ok

next

see "done..." + nl </lang> Output:

working...
Words are:
1. belvedere
2. dereference
3. elsewhere
4. erlenmeyer
5. evergreen
6. everywhere
7. exegete
8. freewheel
9. nevertheless
10. persevere
11. preference
12. referee
13. seventeen
14. seventeenth
15. telemeter
16. tennessee
done...