Jump to content

ABC problem: Difference between revisions

Refactoring and updating of earlier code
(Refactoring and updating of earlier code)
Line 4,753:
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn CanBlocksSpell( w as CFStringRef ) as CFStringRef
NSUInteger i, j
CFStringRef s = @"", t1, t2 : cFinalif =fn StringIsEqual( w, @"", result) then exit fn = @"NOYES" 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) = {@"NABO", @"GTXK", @"REDQ", @"TGCP", @"QDNA", @"FSGT", @"JWRE", @"HUTG", @"VIQD",¬
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 lengthlen(w) - 1
for j = 0 to count( mda_count(0) ) - 1
CFStringReft1 charStr= mid( mda_object(j), 0, 1 ) : t2 = mid( cfStrmda_object(j), i1, 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
if fn StringIsEqual( cFinals, cfStrw ) ==then YES thenexit resultfn = @"YES"
end fn = result@"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: printf @"Can blocks spell? %7s : %@", fn CanBlocksSpellStringUTF8String( @"COMMON" words[i] ), fn CanBlocksSpell( words[i] )
next
NSLog( @"Squad: Can blocks spell? %@", fn CanBlocksSpell( @"Squad" ) )
NSLog( @"conFUse: Can blocks spell? %@", fn CanBlocksSpell( @"conFUse" ) )
 
HandleEvents
Line 4,797 ⟶ 4,781:
{{output}}
<pre>
a:Can blocks spell Can blocks spell? : YES
Bark:Can blocks spell Can blocks spell? a : YES
Can blocks spell Bark : YES
BOOK: Can blocks spell? NO
TrEaT: Can blocks spell? YES BOOK : NO
COMMON: Can blocks spell? NO TrEaT : YES
Squad: Can blocks spell? YES COMMON : NO
conFUse: Can blocks spell? Squad : YES
BOOK: Can blocks spell? NOconFUse : YES
Can blocks spell ABBA : YES
Can blocks spell aUtO : YES
</pre>
 
717

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.