Find words which contain the most consonants: Difference between revisions
Content added Content deleted
(Added Algol 68) |
|||
Line 226: | Line 226: | ||
9 consonants: 1 words |
9 consonants: 1 words |
||
comprehensible</pre> |
comprehensible</pre> |
||
=={{header|ALGOL 68}}== |
|||
<lang algol68># find words longer than 10 characters and sort by the number of consonants # |
|||
# they contain # |
|||
IF FILE input file; |
|||
STRING file name = "unixdict.txt"; |
|||
open( input file, file name, stand in channel ) /= 0 |
|||
THEN |
|||
# failed to open the file # |
|||
print( ( "Unable to open """ + file name + """", newline ) ) |
|||
ELSE |
|||
# file opened OK # |
|||
BOOL at eof := FALSE; |
|||
# set the EOF handler for the file # |
|||
on logical file end( input file |
|||
, ( REF FILE f )BOOL: |
|||
BEGIN # note that we reached EOF on the latest read # |
|||
# and return TRUE so processing can continue # |
|||
at eof := TRUE |
|||
END |
|||
); |
|||
# in-place quick sort an array of strings # |
|||
PROC s quicksort = ( REF[]STRING a, INT lb, ub )VOID: |
|||
IF ub > lb |
|||
THEN |
|||
# more than one element, so must sort # |
|||
INT left := lb; |
|||
INT right := ub; |
|||
# choosing the middle element of the array as the pivot # |
|||
STRING pivot := a[ left + ( ( right + 1 ) - left ) OVER 2 ]; |
|||
WHILE |
|||
WHILE IF left <= ub THEN a[ left ] < pivot ELSE FALSE FI |
|||
DO |
|||
left +:= 1 |
|||
OD; |
|||
WHILE IF right >= lb THEN a[ right ] > pivot ELSE FALSE FI |
|||
DO |
|||
right -:= 1 |
|||
OD; |
|||
left <= right |
|||
DO |
|||
STRING t := a[ left ]; |
|||
a[ left ] := a[ right ]; |
|||
a[ right ] := t; |
|||
left +:= 1; |
|||
right -:= 1 |
|||
OD; |
|||
s quicksort( a, lb, right ); |
|||
s quicksort( a, left, ub ) |
|||
FI # s quicksort # ; |
|||
# returns the length of s # |
|||
OP LENGTH = ( STRING s )INT: 1 + ( UPB s - LWB s ); |
|||
# returns the consonant count of s or 0 if the consonants are not unique # |
|||
OP UNIQUECONSONANTS = ( STRING s )INT: |
|||
BEGIN |
|||
[ 0 : 26 ]INT count; |
|||
FOR c FROM LWB count TO UPB count DO count[ c ] := 0 OD; |
|||
FOR i FROM LWB s TO UPB s DO |
|||
CHAR c := s[ i ]; |
|||
IF c >= "A" AND c <= "Z" THEN |
|||
c := REPR ( ABS c + ( ABS "a" - ABS "A" ) ) |
|||
FI; |
|||
IF c >= "b" AND c <= "z" THEN |
|||
IF c /= "e" AND c /= "i" AND c /= "o" AND c /= "u" THEN |
|||
count[ ABS c - ABS "a" ] +:= 1 |
|||
FI |
|||
FI |
|||
OD; |
|||
BOOL all unique := TRUE; |
|||
INT consonants := 0; |
|||
FOR c FROM LWB count TO UPB count WHILE all unique := count[ c ] < 2 DO |
|||
consonants +:= count[ c ] |
|||
OD; |
|||
IF all unique THEN consonants ELSE 0 FI |
|||
END # UNIQUECONSONANTS # ; |
|||
[ 1 : 2 000 ]STRING words; |
|||
INT w count := 0; |
|||
INT max length := 0; |
|||
WHILE NOT at eof |
|||
DO |
|||
STRING word; |
|||
get( input file, ( word, newline ) ); |
|||
IF NOT at eof THEN |
|||
# have another word # |
|||
IF INT w length = LENGTH word; |
|||
w length > 10 |
|||
THEN |
|||
IF INT consonants = UNIQUECONSONANTS word; |
|||
consonants > 0 |
|||
THEN |
|||
# word is long enough to include and contains only uniue # |
|||
# consonants, store it prefixed by the max abs char # |
|||
# complement of the number of consonants in it, so we # |
|||
# sort the words into reverse consonant count order # |
|||
words[ w count +:= 1 ] := REPR ( max abs char - consonants ) + word; |
|||
IF w length > max length THEN max length := w length FI |
|||
FI |
|||
FI |
|||
FI |
|||
OD; |
|||
close( input file ); |
|||
# sort the words # |
|||
s quicksort( words, 1, w count ); |
|||
# display the words # |
|||
INT prev count := 0; |
|||
INT p count := 0; |
|||
BOOL need nl := FALSE; |
|||
FOR w TO w count DO |
|||
STRING s word = words[ w ]; |
|||
INT count = max abs char - ABS s word[ 1 ]; |
|||
STRING word = s word[ 2 : ]; |
|||
INT w length = LENGTH word; |
|||
IF count /= prev count THEN |
|||
IF need nl THEN print( ( newline ) ) FI; |
|||
print( ( newline, whole( count, 0 ), " consonants:", newline ) ); |
|||
prev count := count; |
|||
p count := 0; |
|||
need nl := FALSE |
|||
FI; |
|||
print( ( " ", " " * ( max length - w length ), word ) ); |
|||
IF ( p count +:= 1 ) MOD 5 /= 0 THEN |
|||
need nl := TRUE |
|||
ELSE |
|||
print( ( newline ) ); |
|||
need nl := FALSE |
|||
FI |
|||
OD |
|||
FI</lang> |
|||
{{out}} |
|||
<pre> |
|||
9 consonants: |
|||
comprehensible |
|||
8 consonants: |
|||
administrable anthropology blameworthy bluestocking boustrophedon |
|||
bricklaying chemisorption christendom claustrophobia compensatory |
|||
comprehensive counterexample demonstrable disciplinary discriminable |
|||
geochemistry hypertensive indecipherable indecomposable indiscoverable |
|||
lexicography manslaughter misanthropic mockingbird monkeyflower |
|||
neuropathology paralinguistic pharmacology pitchblende playwriting |
|||
shipbuilding shortcoming springfield stenography stockholder |
|||
switchblade switchboard switzerland thunderclap |
|||
7 consonants: |
|||
acknowledge algorithmic alphanumeric ambidextrous amphibology |
|||
anchoritism atmospheric autobiography bakersfield bartholomew |
|||
bidirectional bloodstream boardinghouse cartilaginous centrifugal |
|||
chamberlain charlemagne clairvoyant combinatorial compensable |
|||
complaisant conflagrate conglomerate conquistador consumptive |
|||
convertible cosmopolitan counterflow countryside countrywide |
|||
declamatory decomposable decomposition deliquescent description |
|||
descriptive dilogarithm discernible discriminate disturbance |
|||
documentary earthmoving encephalitis endothermic epistemology |
|||
everlasting exchangeable exclamatory exclusionary exculpatory |
|||
explanatory extemporaneous extravaganza filamentary fluorescent |
|||
galvanometer geophysical glycerinate groundskeep herpetology |
|||
heterozygous homebuilding honeysuckle hydrogenate hyperboloid |
|||
impenetrable imperceivable imperishable imponderable impregnable |
|||
improvident improvisation incomparable incompatible incomputable |
|||
incredulity indefatigable indigestible indisputable inexhaustible |
|||
inextricable inhospitable inscrutable jurisdiction lawbreaking |
|||
leatherback leatherneck leavenworth logarithmic loudspeaking |
|||
maidservant malnourished marketplace merchandise methodology |
|||
misanthrope mitochondria molybdenite nearsighted obfuscatory |
|||
oceanography palindromic paradigmatic paramagnetic perfectible |
|||
phraseology politicking predicament presidential problematic |
|||
proclamation promiscuity providential purchasable pythagorean |
|||
quasiparticle quicksilver radiotelephone sedimentary selfadjoint |
|||
serendipity sovereignty subjunctive superfluity terminology |
|||
valedictorian valedictory verisimilitude vigilantism voluntarism |
|||
6 consonants: |
|||
aboveground advantageous adventurous aerodynamic anglophobia |
|||
anisotropic archipelago automorphic baltimorean beneficiary |
|||
borosilicate cabinetmake californium codetermine coextensive |
|||
comparative compilation composition confabulate confederate |
|||
considerate consolidate counterpoise countervail decisionmake |
|||
declamation declaration declarative deemphasize deformation |
|||
deliverance demountable denumerable deoxyribose depreciable |
|||
deprivation destabilize diagnosable diamagnetic dichotomize |
|||
dichotomous disambiguate eigenvector elizabethan encapsulate |
|||
enforceable ephemerides epidemiology evolutionary exceptional |
|||
exclamation exercisable exhaustible exoskeleton expenditure |
|||
experiential exploration fluorescein geometrician hemosiderin |
|||
hereinbelow hermeneutic heterogamous heterogeneous heterosexual |
|||
hexadecimal hexafluoride homebuilder homogeneity housebroken |
|||
icosahedral icosahedron impersonate imprecision improvisate |
|||
inadvisable increasable incredulous indivisible indomitable |
|||
ineradicable inescapable inestimable inexcusable infelicitous |
|||
informatica informative inseparable insuperable ionospheric |
|||
justiciable kaleidescope kaleidoscope legerdemain liquefaction |
|||
loudspeaker machinelike magisterial maladaptive mantlepiece |
|||
manufacture masterpiece meetinghouse meteorology minesweeper |
|||
ministerial multifarious musculature observation patrimonial |
|||
peasanthood pediatrician persecution pertinacious picturesque |
|||
planetarium pleistocene pomegranate predominate prejudicial |
|||
prohibition prohibitive prolegomena prosecution provisional |
|||
provocation publication quasiperiodic reclamation religiosity |
|||
renegotiable residential rooseveltian safekeeping saloonkeeper |
|||
serviceable speedometer subrogation sulfonamide superficial |
|||
superlative teaspoonful trapezoidal tridiagonal troublesome |
|||
vainglorious valediction venturesome vermiculite vocabularian |
|||
warehouseman wisenheimer |
|||
5 consonants: |
|||
acquisition acquisitive acrimonious ceremonious deleterious |
|||
diatomaceous egalitarian equilibrate equilibrium equinoctial |
|||
expeditious hereinabove homogeneous inequitable injudicious |
|||
inoperative inquisitive interviewee leeuwenhoek onomatopoeic |
|||
radioactive requisition |
|||
4 consonants: |
|||
audiovisual bourgeoisie onomatopoeia |
|||
</pre> |
|||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
Line 393: | Line 610: | ||
audiovisual bourgeoisie onomatopoeia |
audiovisual bourgeoisie onomatopoeia |
||
</pre> |
</pre> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||