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 i, j
NSUInteger i, j
CFStringRef cFinal = @"", result = @"NO"
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",¬
@"NA", @"GT", @"RE", @"TG", @"QD", @"FS", @"JW", @"HU", @"VI",¬
@"AN", @"OB", @"ER", @"FS", @"LY", @"PC", @"ZM"] )
mda(0) = {@"BO",@"XK",@"DQ",@"CP",@"NA",@"GT",@"RE",@"TG",@"QD",¬
CFStringRef cfStr = fn StringUppercaseString( w )
@"FS",@"JW",@"HU",@"VI",@"AN",@"OB",@"ER",@"FS",@"LY",@"PC",@"ZM"}
NSUInteger length = fn StringLength( cfStr )
NSUInteger count = fn ArrayCount( blocks )
for i = 0 to length - 1
for i = 0 to len(w) - 1
for j = 0 to count - 1
for j = 0 to ( mda_count(0) ) - 1
CFStringRef charStr = mid( cfStr, i, 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( cFinal, cfStr ) == YES then result = @"YES"
if fn StringIsEqual( s, w ) then exit fn = @"YES"
end fn = result
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" ) )
NSLog( @"COMMON: Can blocks spell? %@", fn CanBlocksSpell( @"COMMON" ) )
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>
a: Can blocks spell? YES
Can blocks spell : YES
Bark: Can blocks spell? YES
Can blocks spell a : YES
Can blocks spell Bark : YES
BOOK: Can blocks spell? NO
TrEaT: Can blocks spell? YES
Can blocks spell BOOK : NO
COMMON: Can blocks spell? NO
Can blocks spell TrEaT : YES
Squad: Can blocks spell? YES
Can blocks spell COMMON : NO
conFUse: Can blocks spell? YES
Can blocks spell Squad : YES
Can blocks spell conFUse : YES
Can blocks spell ABBA : YES
Can blocks spell aUtO : YES
</pre>
</pre>