Find words which contain the most consonants: Difference between revisions

FutureBasic solution added
m (syntax highlighting fixup automation)
(FutureBasic solution added)
Line 1,552:
 
close #1</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
#build WarnOfScopedVars NO
 
local fn Words as CFArrayRef
CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
CFArrayRef array = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
end fn = fn ArrayFilteredArrayUsingPredicate( array, fn PredicateWithFormat( @"self.length > %d", 10 ) )
 
 
local fn StringByDeletingCharactersInSet( inString as CFStringRef, set as CFCharacterSetRef ) as CFStringRef
CFMutableStringRef outString = fn MutableStringWithCapacity(0)
long i, length = len(inString)
for i = 0 to length - 1
unichar c = fn StringCharacterAtIndex( inString, i )
if ( fn CharacterSetCharacterIsMember( set, c ) == NO )
MutableStringAppendFormat( outString, @"%C", c )
end if
next
end fn = outString
 
 
void local fn DoIt
CFArrayRef words = fn Words
CFCharacterSetRef vowelSet = fn CharacterSetWithCharactersInString( @"aeiou" )
CFMutableArrayRef array = fn MutableArrayWithCapacity(0)
long maxCons = 0
CFStringRef wd
for wd in words
CFStringRef wd2 = fn StringByDeletingCharactersInSet( wd, vowelSet )// remove vowels
CFMutableSetRef mutSet = fn MutableSetWithCapacity(0)
long i, length = len(wd2)
for i = 0 to length - 1
MutableSetAddObject( mutSet, mid(wd2,i,1) )
next
if ( length == len(mutSet) ) // if equal lengths, there are no duplicate consonants
if ( length >= maxCons )
if ( length > maxCons ) // more consonants in current word so clear array
MutableArrayRemoveAllObjects( array )
maxCons = length
end if
MutableArrayAddObject( array, wd )
end if
end if
next
print fn ArrayComponentsJoinedByString( array, @"\n" )
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre>
comprehensible
</pre>
 
=={{header|Go}}==
416

edits