ABC problem: Difference between revisions
Content added Content deleted
(Refactoring and updating of earlier code) |
(Updated to conform with FB 7.0.23 and newer) |
||
Line 4,752: | Line 4,752: | ||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
Requires FB 7.0.23 or later |
|||
<syntaxhighlight lang="futurebasic"> |
<syntaxhighlight lang="futurebasic"> |
||
local fn CanBlocksSpell( w as CFStringRef ) as CFStringRef |
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 - 1 |
|||
t1 = mid( mda(j), 0, 1 ) : t2 = mid( mda(j), 1, 1 ) |
|||
if ( fn StringIsEqual( mid( w, i, 1 ), t1 ) ) then s = fn StringByAppendingString( s, t1 ) : mda(j) = @" " : break |
|||
if ( fn StringIsEqual( mid( w, i, 1 ), t2 ) ) then s = fn StringByAppendingString( s, t2 ) : mda(j) = @" " : break |
|||
next |
|||
next |
|||
if fn StringIsEqual( s, w ) then exit fn = @"YES" |
|||
end fn = @"NO" |
end fn = @"NO" |
||
NSUInteger i |
NSUInteger i |
||
CFArrayRef words |
CFArrayRef words |
||
CFStringRef w |
|||
words = @[@"", @"a",@"Bark",@"BOOK",@"TrEaT",@"COMMON",@"Squad",@"conFUse",@"ABBA",@"aUtO"] |
words = @[@"", @"a",@"Bark",@"BOOK",@"TrEaT",@"COMMON",@"Squad",@"conFUse",@"ABBA",@"aUtO"] |
||
for |
for w in words |
||
printf @"Can blocks spell %7s : %@", fn StringUTF8String( w ), fn CanBlocksSpell( w ) |
|||
next |
next |
||
NSLog( @"%@", fn WindowPrintViewString( 1 ) ) |
|||
HandleEvents |
HandleEvents |