Find words which contains more than 3 e vowels: Difference between revisions
(→{{header|Raku}}: Added Raku solution) |
|||
Line 106: | Line 106: | ||
15: telemeter |
15: telemeter |
||
16: tennessee |
16: tennessee |
||
</pre> |
|||
=={{header|Julia}}== |
|||
See Alternade_words#Julia for the foreachword function. |
|||
<lang julia>ecount(word) = count(x -> x == 'e', word) |
|||
vowelcount(word) = count(x -> x in ['a', 'e', 'i', 'o', 'u'], word) |
|||
onlyevowelsmorethan3(word, _) = begin n, m = vowelcount(word), ecount(word); n == m && m > 3 ? word : "" end |
|||
foreachword("unixdict.txt", onlyevowelsmorethan3, colwidth=15, numcols=8) |
|||
</lang>{{out}} |
|||
<pre> |
|||
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel |
|||
nevertheless persevere preference referee seventeen seventeenth telemeter tennessee |
|||
</pre> |
</pre> |
||
Revision as of 08:32, 10 February 2021
- Task
Use the dictionary unixdict.txt
Find words which contains more than three e vowels and contains only e vowels.
Show the output here on this page.
- Metrics
- Counting
- Word frequency
- Letter frequency
- Jewels and stones
- I before E except after C
- Bioinformatics/base count
- Count occurrences of a substring
- Count how many vowels and consonants occur in a string
- Remove/replace
- XXXX redacted
- Conjugate a Latin verb
- Remove vowels from a string
- String interpolation (included)
- Strip block comments
- Strip comments from a string
- Strip a set of characters from a string
- Strip whitespace from a string -- top and tail
- Strip control codes and extended characters from a string
- Anagrams/Derangements/shuffling
- Word wheel
- ABC problem
- Sattolo cycle
- Knuth shuffle
- Ordered words
- Superpermutation minimisation
- Textonyms (using a phone text pad)
- Anagrams
- Anagrams/Deranged anagrams
- Permutations/Derangements
- Find/Search/Determine
- ABC words
- Odd words
- Word ladder
- Semordnilap
- Word search
- Wordiff (game)
- String matching
- Tea cup rim text
- Alternade words
- Changeable words
- State name puzzle
- String comparison
- Unique characters
- Unique characters in each string
- Extract file extension
- Levenshtein distance
- Palindrome detection
- Common list elements
- Longest common suffix
- Longest common prefix
- Compare a list of strings
- Longest common substring
- Find common directory path
- Words from neighbour ones
- Change e letters to i in words
- Non-continuous subsequences
- Longest common subsequence
- Longest palindromic substrings
- Longest increasing subsequence
- Words containing "the" substring
- Sum of the digits of n is substring of n
- Determine if a string is numeric
- Determine if a string is collapsible
- Determine if a string is squeezable
- Determine if a string has all unique characters
- Determine if a string has all the same characters
- Longest substrings without repeating characters
- Find words which contains all the vowels
- Find words which contains most consonants
- Find words which contains more than 3 vowels
- Find words which first and last three letters are equals
- Find words which odd letters are consonants and even letters are vowels or vice_versa
- Formatting
- Substring
- Rep-string
- Word wrap
- String case
- Align columns
- Literals/String
- Repeat a string
- Brace expansion
- Brace expansion using ranges
- Reverse a string
- Phrase reversals
- Comma quibbling
- Special characters
- String concatenation
- Substring/Top and tail
- Commatizing numbers
- Reverse words in a string
- Suffixation of decimal numbers
- Long literals, with continuations
- Numerical and alphabetical suffixes
- Abbreviations, easy
- Abbreviations, simple
- Abbreviations, automatic
- Song lyrics/poems/Mad Libs/phrases
- Mad Libs
- Magic 8-ball
- 99 Bottles of Beer
- The Name Game (a song)
- The Old lady swallowed a fly
- The Twelve Days of Christmas
- Tokenize
- Text between
- Tokenize a string
- Word break problem
- Tokenize a string with escaping
- Split a character string based on change of character
- Sequences
Factor
<lang factor>USING: formatting io io.encodings.ascii io.files kernel math sequences ;
"unixdict.txt" ascii file-lines [ [ "aiou" member? ] any? ] reject [ [ CHAR: e = ] count 3 > ] filter [ 1 + "%2d: " printf print ] each-index</lang>
- Output:
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
Go
<lang go>package main
import (
"bytes" "fmt" "io/ioutil" "log" "strings" "unicode/utf8"
)
func main() {
wordList := "unixdict.txt" b, err := ioutil.ReadFile(wordList) if err != nil { log.Fatal("Error reading file") } bwords := bytes.Fields(b) var words []string
outer:
for _, bword := range bwords { s := string(bword) if utf8.RuneCountInString(s) >= 4 { for _, c := range s { if strings.ContainsRune("aiou", c) { continue outer } } words = append(words, s) } } wcount := 0 for _, word := range words { ecount := 0 for _, c := range word { if c == 'e' { ecount++ } } if ecount > 3 { wcount++ fmt.Printf("%2d: %s\n", wcount, word) } }
}</lang>
- Output:
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
Julia
See Alternade_words#Julia for the foreachword function. <lang julia>ecount(word) = count(x -> x == 'e', word) vowelcount(word) = count(x -> x in ['a', 'e', 'i', 'o', 'u'], word) onlyevowelsmorethan3(word, _) = begin n, m = vowelcount(word), ecount(word); n == m && m > 3 ? word : "" end
foreachword("unixdict.txt", onlyevowelsmorethan3, colwidth=15, numcols=8)
</lang>
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
Phix
<lang Phix>function note(string word) return find_any("aiou",word)=0 and length(find_all('e',word))>3 end function sequence notes = filter(get_text("demo/unixdict.txt",GT_LF_STRIPPED),note) printf(1,"%d words: %s\n",{length(notes),join(shorten(notes,"",3))})</lang>
- Output:
16 words: belvedere dereference elsewhere ... seventeenth telemeter tennessee
Raku
<lang perl6>.say for "unixdict.txt".IO.lines.grep: { !/<[aiou]>/ and /e.*e.*e.*e/ };</lang>
- Output:
belvedere dereference elsewhere erlenmeyer evergreen everywhere exegete freewheel nevertheless persevere preference referee seventeen seventeenth telemeter tennessee
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 vowel to be specified, and also the minimum number of the specific 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 /*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...
Wren
<lang ecmascript>import "io" for File import "/fmt" for Fmt
var hasAIOU = Fn.new { |word| word.any { |c| "aiou".contains(c) } } var wordList = "unixdict.txt" // local copy var words = File.read(wordList).trimEnd().split("\n").where { |w| w.count >= 4 && !hasAIOU.call(w) }.toList var count = 0 for (word in words) {
if (word.count { |c| c == "e" } > 3) { count = count + 1 Fmt.print("$2d: $s", count, word) }
}</lang>
- Output:
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