Find words which contain the most consonants: Difference between revisions
Line 16: | Line 16: | ||
mostc(word) = [-length(filter(consonant, word)), word] |
mostc(word) = [-length(filter(consonant, word)), word] |
||
const res = sort(map(mostc, filter(over10sc, split(read("unixdict.txt", String), r"\s+")))) |
const res = sort(map(mostc, filter(over10sc, split(read("unixdict.txt", String), r"\s+")))) |
||
println(" |
println(length(res), " words found.\n\nWord Consonants\n----------------------") |
||
foreach(a -> println(rpad(a[2], 16), -a[1]), res) |
foreach(a -> println(rpad(a[2], 16), -a[1]), res) |
||
</lang>{{out}} |
</lang>{{out}} |
||
<pre> |
<pre> |
||
347 words found. |
|||
Word Consonants |
Word Consonants |
||
---------------------- |
---------------------- |
Revision as of 21:32, 15 February 2021
- Task
Use the dictionary unixdict.txt
Find the words which contains most consonants, but each consonant should appear only once in a word.
The length of any word shown should have a length > 10.
Julia
<lang julia>consonant(ch) = !(ch in ['a', 'e', 'i', 'o', 'u']) singlec(consonants) = length(unique(consonants)) == length(consonants) over10sc(word) = length(word) > 10 && singlec(filter(consonant, word)) mostc(word) = [-length(filter(consonant, word)), word] const res = sort(map(mostc, filter(over10sc, split(read("unixdict.txt", String), r"\s+")))) println(length(res), " words found.\n\nWord Consonants\n----------------------") foreach(a -> println(rpad(a[2], 16), -a[1]), res)
</lang>
- Output:
347 words found. Word Consonants ---------------------- comprehensible 9 administrable 8 anthropology 8 blameworthy 8 bluestocking 8 boustrophedon 8 bricklaying 8 chemisorption 8 christendom 8 claustrophobia 8 compensatory 8 comprehensive 8 counterexample 8 -- multiple lines deleted -- audiovisual 4 bourgeoisie 4 onomatopoeia 4
Phix
<lang Phix>function consonant(integer ch) return find(ch,"aeiou")=0 end function function singlec(string consonants) return length(unique(consonants))=length(consonants) end function function over10sc(string word) return length(word)>10 and singlec(filter(word,consonant)) end function function mostc(string word) return {length(filter(word,consonant)),word} end function sequence res = sort_columns(apply(filter(get_text("demo/unixdict.txt",GT_LF_STRIPPED),over10sc),mostc),{-1,2}) printf(1,"%d most consonant words: %v\n",{length(res),shorten(res,"",2)})</lang>
- Output:
347 most consonant words: {{9,"comprehensible"},{8,"administrable"},"...",{4,"bourgeoisie"},{4,"onomatopoeia"}}
REXX
<lang rexx>/*REXX pgm finds words (within an identified dict.) which contain the most consonants.*/ parse arg minl iFID . /*obtain optional arguments from the CL*/ if minl== | minl=="," then minl= 11 /*Not specified? Then use the default.*/ if iFID== | iFID=="," then iFID='unixdict.txt' /* " " " " " " */
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 /*#*/
- = # - 1 /*adjust word count because of DO loop.*/
say copies('─', 30) # "words in the dictionary file: " iFID xyz= 'bcdfghjklmnpqrstvwxyz'; upper xyz /*list of the 21 uppercase consonants. */ L= length(xyz) /*number of consonants in the alphabet.*/ maxCnt= 0 /*max # unique consonants in a max set.*/ !.=; !!.= 0 /* " " " " " " word. */
do j=1 for #; $= @.j; upper $ /*obtain an uppercased word from dict. */ if length($)<minl then iterate /*Is word long enough? No, then skip.*/ cnt= 0 /*the number of consonants (so far). */
do k=1 for L; q= substr(xyz, K, 1) /*examine all consonants for uniqueness*/ _= pos(q, $) if _==0 then iterate /*Is this consonant present? No, skip.*/ if pos(q, $, _ + 1)>0 then iterate j /*More than 1 same consonant? Then skip*/ cnt= cnt + 1 /*bump the number of consonants so far.*/ end /*k*/
!.cnt= !.cnt @.j /*append a word to a specific len list.*/ !!.cnt= cnt /*keep track of # of unique consonants.*/ maxCnt= max(maxCNT, cnt) /*save the maximum count (so far). */ end /*j*/ /*show sets of words, unique consonants*/ do m=maxCnt to 1 by -1; n= words(!.m) /*get the number of words in this set. */ if n==0 then iterate /*Any word in this set? No, then skip.*/ say; say; say /*show some blank lines between sets. */ do y=1 for n /*show individual words in the set. */ say right(y, L#)':' right( left( word(!.m, y), 30), 40) /*indent words.*/ end /*y*/
say copies('─', 30) n " word"s(n) 'found which have ' !!.m " unique" , "consonants and having a minimum word length of: " minl end /*m*/
exit 0 /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ s: if arg(1)==1 then return arg(3); return word( arg(2) 's', 1)</lang>
- output when using the default inputs:
(Shown at three-quarter size.)
────────────────────────────── 25104 words in the dictionary file: unixdict.txt 1: comprehensible ────────────────────────────── 1 word found which have 9 unique consonants and having a minimum word length of: 11 1: administrable 2: anthropology 3: blameworthy 4: bluestocking 5: boustrophedon 6: bricklaying 7: chemisorption 8: christendom 9: claustrophobia 10: compensatory 11: comprehensive 12: counterexample 13: demonstrable 14: disciplinary 15: discriminable 16: geochemistry 17: hypertensive 18: indecipherable 19: indecomposable 20: indiscoverable 21: lexicography 22: manslaughter 23: misanthropic 24: mockingbird 25: monkeyflower 26: neuropathology 27: paralinguistic 28: pharmacology 29: pitchblende 30: playwriting 31: shipbuilding 32: shortcoming 33: springfield 34: stenography 35: stockholder 36: switchblade 37: switchboard 38: switzerland 39: thunderclap ────────────────────────────── 39 words found which have 8 unique consonants and having a minimum word length of: 11 1: acknowledge 2: algorithmic 3: alphanumeric 4: ambidextrous 5: amphibology 6: anchoritism 7: atmospheric 8: autobiography 9: bakersfield 10: bartholomew 11: bidirectional 12: bloodstream 13: boardinghouse 14: cartilaginous 15: centrifugal 16: chamberlain 17: charlemagne 18: clairvoyant 19: combinatorial 20: compensable 21: complaisant 22: conflagrate 23: conglomerate 24: conquistador 25: consumptive 26: convertible 27: cosmopolitan 28: counterflow 29: countryside 30: countrywide 31: declamatory 32: decomposable 33: decomposition 34: deliquescent 35: description 36: descriptive 37: dilogarithm 38: discernible 39: discriminate 40: disturbance 41: documentary 42: earthmoving 43: encephalitis 44: endothermic 45: epistemology 46: everlasting 47: exchangeable 48: exclamatory 49: exclusionary 50: exculpatory 51: explanatory 52: extemporaneous 53: extravaganza 54: filamentary 55: fluorescent 56: galvanometer 57: geophysical 58: glycerinate 59: groundskeep 60: herpetology 61: heterozygous 62: homebuilding 63: honeysuckle 64: hydrogenate 65: hyperboloid 66: impenetrable 67: imperceivable 68: imperishable 69: imponderable 70: impregnable 71: improvident 72: improvisation 73: incomparable 74: incompatible 75: incomputable 76: incredulity 77: indefatigable 78: indigestible 79: indisputable 80: inexhaustible 81: inextricable 82: inhospitable 83: inscrutable 84: jurisdiction 85: lawbreaking 86: leatherback 87: leatherneck 88: leavenworth 89: logarithmic 90: loudspeaking 91: maidservant 92: malnourished 93: marketplace 94: merchandise 95: methodology 96: misanthrope 97: mitochondria 98: molybdenite 99: nearsighted 100: obfuscatory 101: oceanography 102: palindromic 103: paradigmatic 104: paramagnetic 105: perfectible 106: phraseology 107: politicking 108: predicament 109: presidential 110: problematic 111: proclamation 112: promiscuity 113: providential 114: purchasable 115: pythagorean 116: quasiparticle 117: quicksilver 118: radiotelephone 119: sedimentary 120: selfadjoint 121: serendipity 122: sovereignty 123: subjunctive 124: superfluity 125: terminology 126: valedictorian 127: valedictory 128: verisimilitude 129: vigilantism 130: voluntarism ────────────────────────────── 130 words found which have 7 unique consonants and having a minimum word length of: 11 1: aboveground 2: advantageous 3: adventurous 4: aerodynamic 5: anglophobia 6: anisotropic 7: archipelago 8: automorphic 9: baltimorean 10: beneficiary 11: borosilicate 12: cabinetmake 13: californium 14: codetermine 15: coextensive 16: comparative 17: compilation 18: composition 19: confabulate 20: confederate 21: considerate 22: consolidate 23: counterpoise 24: countervail 25: decisionmake 26: declamation 27: declaration 28: declarative 29: deemphasize 30: deformation 31: deliverance 32: demountable 33: denumerable 34: deoxyribose 35: depreciable 36: deprivation 37: destabilize 38: diagnosable 39: diamagnetic 40: dichotomize 41: dichotomous 42: disambiguate 43: eigenvector 44: elizabethan 45: encapsulate 46: enforceable 47: ephemerides 48: epidemiology 49: evolutionary 50: exceptional 51: exclamation 52: exercisable 53: exhaustible 54: exoskeleton 55: expenditure 56: experiential 57: exploration 58: fluorescein 59: geometrician 60: hemosiderin 61: hereinbelow 62: hermeneutic 63: heterogamous 64: heterogeneous 65: heterosexual 66: hexadecimal 67: hexafluoride 68: homebuilder 69: homogeneity 70: housebroken 71: icosahedral 72: icosahedron 73: impersonate 74: imprecision 75: improvisate 76: inadvisable 77: increasable 78: incredulous 79: indivisible 80: indomitable 81: ineradicable 82: inescapable 83: inestimable 84: inexcusable 85: infelicitous 86: informatica 87: informative 88: inseparable 89: insuperable 90: ionospheric 91: justiciable 92: kaleidescope 93: kaleidoscope 94: legerdemain 95: liquefaction 96: loudspeaker 97: machinelike 98: magisterial 99: maladaptive 100: mantlepiece 101: manufacture 102: masterpiece 103: meetinghouse 104: meteorology 105: minesweeper 106: ministerial 107: multifarious 108: musculature 109: observation 110: patrimonial 111: peasanthood 112: pediatrician 113: persecution 114: pertinacious 115: picturesque 116: planetarium 117: pleistocene 118: pomegranate 119: predominate 120: prejudicial 121: prohibition 122: prohibitive 123: prolegomena 124: prosecution 125: provisional 126: provocation 127: publication 128: quasiperiodic 129: reclamation 130: religiosity 131: renegotiable 132: residential 133: rooseveltian 134: safekeeping 135: saloonkeeper 136: serviceable 137: speedometer 138: subrogation 139: sulfonamide 140: superficial 141: superlative 142: teaspoonful 143: trapezoidal 144: tridiagonal 145: troublesome 146: vainglorious 147: valediction 148: venturesome 149: vermiculite 150: vocabularian 151: warehouseman 152: wisenheimer ────────────────────────────── 152 words found which have 6 unique consonants and having a minimum word length of: 11 1: acquisition 2: acquisitive 3: acrimonious 4: ceremonious 5: deleterious 6: diatomaceous 7: egalitarian 8: equilibrate 9: equilibrium 10: equinoctial 11: expeditious 12: hereinabove 13: homogeneous 14: inequitable 15: injudicious 16: inoperative 17: inquisitive 18: interviewee 19: leeuwenhoek 20: onomatopoeic 21: radioactive 22: requisition ────────────────────────────── 22 words found which have 5 unique consonants and having a minimum word length of: 11 1: audiovisual 2: bourgeoisie 3: onomatopoeia ────────────────────────────── 3 words found which have 4 unique consonants and having a minimum word length of: 11
Ring
<lang ring> load "stdlib.ring"
cStr = read("unixdict.txt") wordList = str2list(cStr) consonants = [] result = [] num = 0
see "working..." + nl
ln = len(wordList) for n = ln to 1 step -1
if len(wordList[n]) < 11 del(wordList,n) ok
next
for n = 1 to len(wordList)
flag = 1 numcon = 0 str = wordList[n] for m = 1 to len(str) - 1 for p = m+1 to len(str) if not isvowel(str[m]) and (str[m] = str[p]) flag = 0 exit 2 ok next next if flag = 1 add(consonants,wordList[n]) ok
next
for n = 1 to len(consonants)
con = 0 str = consonants[n] for m = 1 to len(str) if not isvowel(str[m]) con = con + 1 ok next add(result,[consonants[n],con])
next
result = sort(result,2) result = reverse(result)
for n = 1 to len(result)
see "" + n + ". " + result[n][1] + " " + result[n][2] + nl
next
see "done..." + nl </lang>
- Output:
working... 1. comprehensible 9 2. indecipherable 8 3. boustrophedon 8 4. bricklaying 8 5. demonstrable 8 6. chemisorption 8 7. indecomposable 8 8. indiscoverable 8 9. discriminable 8 10. shipbuilding 8 .... 50. deliquescent 7 51. inscrutable 7 52. declamatory 7 53. decomposition 7 54. decomposable 7 55. leatherback 7 56. exclusionary 7 57. convertible 7 58. exculpatory 7 59. loudspeaking 7 60. consumptive 7 ... 180. eigenvector 6 181. exceptional 6 182. archipelago 6 183. anisotropic 6 184. encapsulate 6 185. evolutionary 6 186. elizabethan 6 187. declaration 6 188. declarative 6 189. declamation 6 190. comparative 6 ... 330. equilibrium 5 331. equinoctial 5 332. onomatopoeic 5 333. inequitable 5 334. requisition 5 335. diatomaceous 5 336. homogeneous 5 337. radioactive 5 338. deleterious 5 339. inoperative 5 340. inquisitive 5 .... 345. audiovisual 4 346. onomatopoeia 4 347. bourgeoisie 4 done...