Find words which contain the most consonants
- 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(x -> mostc(x), filter(over10sc, split(read("unixdict.txt", String), r"\s+")))) println("Word Consonants\n----------------------") foreach(a -> println(rpad(a[2], 16), -a[1]), res)
</lang>
- Output:
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 demonstrable 8 disciplinary 8 discriminable 8 geochemistry 8 hypertensive 8 indecipherable 8 indecomposable 8 indiscoverable 8 lexicography 8 manslaughter 8 misanthropic 8 mockingbird 8 monkeyflower 8 neuropathology 8 paralinguistic 8 pharmacology 8 pitchblende 8 playwriting 8 shipbuilding 8 shortcoming 8 springfield 8 stenography 8 stockholder 8 switchblade 8 switchboard 8 switzerland 8 thunderclap 8 acknowledge 7 algorithmic 7 alphanumeric 7 ambidextrous 7 amphibology 7 anchoritism 7 atmospheric 7 autobiography 7 bakersfield 7 bartholomew 7 bidirectional 7 bloodstream 7 boardinghouse 7 cartilaginous 7 centrifugal 7 chamberlain 7 charlemagne 7 clairvoyant 7 combinatorial 7 compensable 7 complaisant 7 conflagrate 7 conglomerate 7 conquistador 7 consumptive 7 convertible 7 cosmopolitan 7 counterflow 7 countryside 7 countrywide 7 declamatory 7 decomposable 7 decomposition 7 deliquescent 7 description 7 descriptive 7 dilogarithm 7 discernible 7 discriminate 7 disturbance 7 documentary 7 earthmoving 7 encephalitis 7 endothermic 7 epistemology 7 everlasting 7 exchangeable 7 exclamatory 7 exclusionary 7 exculpatory 7 explanatory 7 extemporaneous 7 extravaganza 7 filamentary 7 fluorescent 7 galvanometer 7 geophysical 7 glycerinate 7 groundskeep 7 herpetology 7 heterozygous 7 homebuilding 7 honeysuckle 7 hydrogenate 7 hyperboloid 7 impenetrable 7 imperceivable 7 imperishable 7 imponderable 7 impregnable 7 improvident 7 improvisation 7 incomparable 7 incompatible 7 incomputable 7 incredulity 7 indefatigable 7 indigestible 7 indisputable 7 inexhaustible 7 inextricable 7 inhospitable 7 inscrutable 7 jurisdiction 7 lawbreaking 7 leatherback 7 leatherneck 7 leavenworth 7 logarithmic 7 loudspeaking 7 maidservant 7 malnourished 7 marketplace 7 merchandise 7 methodology 7 misanthrope 7 mitochondria 7 molybdenite 7 nearsighted 7 obfuscatory 7 oceanography 7 palindromic 7 paradigmatic 7 paramagnetic 7 perfectible 7 phraseology 7 politicking 7 predicament 7 presidential 7 problematic 7 proclamation 7 promiscuity 7 providential 7 purchasable 7 pythagorean 7 quasiparticle 7 quicksilver 7 radiotelephone 7 sedimentary 7 selfadjoint 7 serendipity 7 sovereignty 7 subjunctive 7 superfluity 7 terminology 7 valedictorian 7 valedictory 7 verisimilitude 7 vigilantism 7 voluntarism 7 aboveground 6 advantageous 6 adventurous 6 aerodynamic 6 anglophobia 6 anisotropic 6 archipelago 6 automorphic 6 baltimorean 6 beneficiary 6 borosilicate 6 cabinetmake 6 californium 6 codetermine 6 coextensive 6 comparative 6 compilation 6 composition 6 confabulate 6 confederate 6 considerate 6 consolidate 6 counterpoise 6 countervail 6 decisionmake 6 declamation 6 declaration 6 declarative 6 deemphasize 6 deformation 6 deliverance 6 demountable 6 denumerable 6 deoxyribose 6 depreciable 6 deprivation 6 destabilize 6 diagnosable 6 diamagnetic 6 dichotomize 6 dichotomous 6 disambiguate 6 eigenvector 6 elizabethan 6 encapsulate 6 enforceable 6 ephemerides 6 epidemiology 6 evolutionary 6 exceptional 6 exclamation 6 exercisable 6 exhaustible 6 exoskeleton 6 expenditure 6 experiential 6 exploration 6 fluorescein 6 geometrician 6 hemosiderin 6 hereinbelow 6 hermeneutic 6 heterogamous 6 heterogeneous 6 heterosexual 6 hexadecimal 6 hexafluoride 6 homebuilder 6 homogeneity 6 housebroken 6 icosahedral 6 icosahedron 6 impersonate 6 imprecision 6 improvisate 6 inadvisable 6 increasable 6 incredulous 6 indivisible 6 indomitable 6 ineradicable 6 inescapable 6 inestimable 6 inexcusable 6 infelicitous 6 informatica 6 informative 6 inseparable 6 insuperable 6 ionospheric 6 justiciable 6 kaleidescope 6 kaleidoscope 6 legerdemain 6 liquefaction 6 loudspeaker 6 machinelike 6 magisterial 6 maladaptive 6 mantlepiece 6 manufacture 6 masterpiece 6 meetinghouse 6 meteorology 6 minesweeper 6 ministerial 6 multifarious 6 musculature 6 observation 6 patrimonial 6 peasanthood 6 pediatrician 6 persecution 6 pertinacious 6 picturesque 6 planetarium 6 pleistocene 6 pomegranate 6 predominate 6 prejudicial 6 prohibition 6 prohibitive 6 prolegomena 6 prosecution 6 provisional 6 provocation 6 publication 6 quasiperiodic 6 reclamation 6 religiosity 6 renegotiable 6 residential 6 rooseveltian 6 safekeeping 6 saloonkeeper 6 serviceable 6 speedometer 6 subrogation 6 sulfonamide 6 superficial 6 superlative 6 teaspoonful 6 trapezoidal 6 tridiagonal 6 troublesome 6 vainglorious 6 valediction 6 venturesome 6 vermiculite 6 vocabularian 6 warehouseman 6 wisenheimer 6 acquisition 5 acquisitive 5 acrimonious 5 ceremonious 5 deleterious 5 diatomaceous 5 egalitarian 5 equilibrate 5 equilibrium 5 equinoctial 5 expeditious 5 hereinabove 5 homogeneous 5 inequitable 5 injudicious 5 inoperative 5 inquisitive 5 interviewee 5 leeuwenhoek 5 onomatopoeic 5 radioactive 5 requisition 5 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...