ABC problem: Difference between revisions
Content added Content deleted
(Refactoring and updating of earlier code) |
|||
Line 4,753: | Line 4,753: | ||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
<syntaxhighlight lang="futurebasic"> |
<syntaxhighlight lang="futurebasic"> |
||
include "NSLog.incl" |
|||
local fn CanBlocksSpell( w as CFStringRef ) as CFStringRef |
local fn CanBlocksSpell( w as CFStringRef ) as CFStringRef |
||
NSUInteger |
NSUInteger i, j |
||
CFStringRef |
CFStringRef s = @"", t1, t2 : if fn StringIsEqual( w, @"" ) then exit fn = @"YES" else w = ucase(w) |
||
CFMutableArrayRef blocks |
|||
blocks = fn MutableArrayWithArray( @[@"BO", @"XK", @"DQ", @"CP",¬ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
CFStringRef cfStr = fn StringUppercaseString( w ) |
|||
⚫ | |||
NSUInteger length = fn StringLength( cfStr ) |
|||
NSUInteger count = fn ArrayCount( blocks ) |
|||
for i = 0 to |
for i = 0 to len(w) - 1 |
||
for j = 0 to |
for j = 0 to ( mda_count(0) ) - 1 |
||
t1 = mid( mda_object(j), 0, 1 ) : t2 = mid( mda_object(j), 1, 1 ) |
|||
if ( fn StringIsEqual( mid( w, i, 1 ), t1 ) ) then s = fn StringByAppendingString( s, t1 ) : mda(j) = @" " : exit for |
|||
CFStringRef compareStr = fn ArrayObjectAtIndex( blocks, j ) |
|||
if ( fn StringIsEqual( mid( w, i, 1 ), t2 ) ) then s = fn StringByAppendingString( s, t2 ) : mda(j) = @" " : exit for |
|||
CFStringRef testStr1 = mid( compareStr, 0, 1 ) |
|||
CFStringRef testStr2 = mid( compareStr, 1, 1 ) |
|||
if ( fn StringIsEqual( charStr, testStr1 ) == YES ) |
|||
cFinal = fn StringByAppendingString( cFinal, testStr1 ) : MutableArrayReplaceObjectAtIndex( blocks, @" ", j ) : exit for |
|||
end if |
|||
if ( fn StringIsEqual( charStr, testStr2 ) == YES ) |
|||
cFinal = fn StringByAppendingString( cFinal, testStr2 ) : MutableArrayReplaceObjectAtIndex( blocks, @" ", j ) : exit for |
|||
end if |
|||
next |
next |
||
next |
next |
||
if fn StringIsEqual( |
if fn StringIsEqual( s, w ) then exit fn = @"YES" |
||
end fn = |
end fn = @"NO" |
||
NSUInteger i |
|||
NSLog( @"a: Can blocks spell? %@", fn CanBlocksSpell( @"a" ) ) |
|||
CFArrayRef words |
|||
NSLog( @"Bark: Can blocks spell? %@", fn CanBlocksSpell( @"Bark" ) ) |
|||
words = @[@"", @"a",@"Bark",@"BOOK",@"TrEaT",@"COMMON",@"Squad",@"conFUse",@"ABBA",@"aUtO"] |
|||
NSLog( @"BOOK: Can blocks spell? %@", fn CanBlocksSpell( @"BOOK" ) ) |
|||
for i = 0 to len(words) -1 |
|||
NSLog( @"TrEaT: Can blocks spell? %@", fn CanBlocksSpell( @"TrEaT" ) ) |
|||
printf @"Can blocks spell %7s : %@", fn StringUTF8String( words[i] ), fn CanBlocksSpell( words[i] ) |
|||
next |
|||
NSLog( @"Squad: Can blocks spell? %@", fn CanBlocksSpell( @"Squad" ) ) |
|||
NSLog( @"conFUse: Can blocks spell? %@", fn CanBlocksSpell( @"conFUse" ) ) |
|||
HandleEvents |
HandleEvents |
||
Line 4,797: | Line 4,781: | ||
{{output}} |
{{output}} |
||
<pre> |
<pre> |
||
Can blocks spell : YES |
|||
Can blocks spell a : YES |
|||
Can blocks spell Bark : YES |
|||
⚫ | |||
Can blocks spell BOOK : NO |
|||
Can blocks spell TrEaT : YES |
|||
Can blocks spell COMMON : NO |
|||
Can blocks spell Squad : YES |
|||
⚫ | |||
Can blocks spell ABBA : YES |
|||
Can blocks spell aUtO : YES |
|||
</pre> |
</pre> |
||