ABC problem: Difference between revisions

Updated to conform with FB 7.0.23 and newer
(Refactoring and updating of earlier code)
(Updated to conform with FB 7.0.23 and newer)
Line 4,752:
 
=={{header|FutureBasic}}==
Requires FB 7.0.23 or later
<syntaxhighlight lang="futurebasic">
local fn CanBlocksSpell( w as CFStringRef ) as CFStringRef
NSUInteger i, j
CFStringRef s = @"", t1, t2 : if fn StringIsEqual( w, @"" ) then exit fn = @"YES" else w = ucase(w)
 
mda(0) = {@"BO",@"XK",@"DQ",@"CP",@"NA",@"GT",@"RE",@"TG",@"QD",¬
@"FS",@"JW",@"HU",@"VI",@"AN",@"OB",@"ER",@"FS",@"LY",@"PC",@"ZM"}
 
for i = 0 to len(w) - 1
for j = 0 to ( mda_count(0) ) - 1
t1 = mid( mda_objectmda(j), 0, 1 ) : t2 = mid( mda_objectmda(j), 1, 1 )
if ( fn StringIsEqual( mid( w, i, 1 ), t1 ) ) then s = fn StringByAppendingString( s, t1 ) : mda(j) = @" " : exit forbreak
if ( fn StringIsEqual( mid( w, i, 1 ), t2 ) ) then s = fn StringByAppendingString( s, t2 ) : mda(j) = @" " : exit forbreak
next
next
if fn StringIsEqual( s, w ) then exit fn = @"YES"
end fn = @"NO"
 
NSUInteger i
CFArrayRef words
CFStringRef w
words = @[@"", @"a",@"Bark",@"BOOK",@"TrEaT",@"COMMON",@"Squad",@"conFUse",@"ABBA",@"aUtO"]
for iw =in 0 to len(words) -1
printf @"Can blocks spell %7s : %@", fn StringUTF8String( words[i]w ), fn CanBlocksSpell( words[i]w )
next
 
NSLog( @"%@", fn WindowPrintViewString( 1 ) )
 
 
HandleEvents
715

edits