ABC problem: Difference between revisions

Content added Content deleted
Line 4,518: Line 4,518:
include "NSLog.incl"
include "NSLog.incl"


local fn CanSpell( w as CFStringRef ) as CFStringRef
local fn CanBlocksSpell( w as CFStringRef ) as CFStringRef
NSUInteger i, j, length, count
NSUInteger i, j
CFStringRef cFinal = @"", result = @"NO"
Boolean letterFound
CFMutableArrayRef blocks
CFStringRef result = @"YES"
CFArrayRef blocks = @[@[@"B", @"O"], @[@"X", @"K"], @[@"D", @"Q"], @[@"C", @"P"]
blocks = fn MutableArrayWithArray( @[@"BO", @"XK", @"DQ", @"CP",¬
@[@"N", @"A"], @[@"G", @"T"], @[@"R", @"E"], @[@"T", @"G"], @[@"Q", @"D"], @[@"F", @"S"]
@"NA", @"GT", @"RE", @"TG", @"QD", @"FS", @"JW", @"HU", @"VI",¬
@[@"J", @"W"], @[@"H", @"U"], @[@"V", @"I"], @[@"A", @"N"], @[@"O", @"B"], @[@"E", @"R"],¬
@"AN", @"OB", @"ER", @"FS", @"LY", @"PC", @"ZM"] )
@[@"F", @"S"], @[@"L", @"Y"], @[@"P", @"C"], @[@"Z", @"M"]]
CFStringRef testWord = fn StringUppercaseString( w )
CFStringRef cfStr = fn StringUppercaseString( w )
NSUInteger length = fn StringLength( cfStr )
length = fn StringLength( testWord )
NSUInteger count = fn ArrayCount( blocks )
count = fn ArrayCount( blocks )
for i = 0 to length - 1
for i = 0 to length - 1
letterFound = NO
for j = 0 to count - 1
for j = 0 to count - 1
CFStringRef subString = mid( testWord, i, 1 )
CFStringRef charStr = mid( cfStr, i, 1 )
CFStringRef compareStr = fn ArrayObjectAtIndex( blocks, j )
// NSLog( @"%@\n", subString )
CFArrayRef tempArr = fn ArrayObjectAtIndex( blocks, j )
CFStringRef testStr1 = mid( compareStr, 0, 1 )
NSLog( @"%@; %@ %@", subString, tempArr[0], tempArr[1] )
CFStringRef testStr2 = mid( compareStr, 1, 1 )
if not letterFound and ( subString == tempArr[0] ) or ( substring == tempArr[1] )
if ( fn StringIsEqual( charStr, testStr1 ) == YES )
cFinal = fn StringByAppendingString( cFinal, testStr1 ) : MutableArrayReplaceObjectAtIndex( blocks, @" ", j ) : exit for
//tempArr[0] = -1
//tempArr[1] = -1
end if
letterFound = YES
if ( fn StringIsEqual( charStr, testStr2 ) == YES )
cFinal = fn StringByAppendingString( cFinal, testStr2 ) : MutableArrayReplaceObjectAtIndex( blocks, @" ", j ) : exit for
end if
end if
next
next
if ( not letterFound ) then result = @"NO" : exit fn
next
next
if fn StringIsEqual( cFinal, cfStr ) == YES then result = @"YES"
end fn = result
end fn = result


NSLog( @"a: Can blocks spell? %@", fn CanBlocksSpell( @"a" ) )

NSLog( @"a: %@\n", fn CanSpell( @"a" ) )
NSLog( @"Bark: Can blocks spell? %@", fn CanBlocksSpell( @"Bark" ) )
NSLog( @"Bark: %@\n", fn CanSpell( @"Bark" ) )
NSLog( @"BOOK: Can blocks spell? %@", fn CanBlocksSpell( @"BOOK" ) )
NSLog( @"bOok: %@\n", fn CanSpell( @"bOok" ) )
NSLog( @"TrEaT: Can blocks spell? %@", fn CanBlocksSpell( @"TrEaT" ) )
NSLog( @"treat: %@\n", fn CanSpell( @"treat" ) )
NSLog( @"COMMON: Can blocks spell? %@", fn CanBlocksSpell( @"COMMON" ) )
NSLog( @"COMMON: %@\n", fn CanSpell( @"COMMON" ) )
NSLog( @"Squad: Can blocks spell? %@", fn CanBlocksSpell( @"Squad" ) )
NSLog( @"squad: %@\n", fn CanSpell( @"squad" ) )
NSLog( @"conFUse: Can blocks spell? %@", fn CanBlocksSpell( @"conFUse" ) )
NSLog( @"cnfuse: %@\n", fn CanSpell( @"cnfuse" ) )



HandleEvents
HandleEvents