41 lines
1.2 KiB
Text
41 lines
1.2 KiB
Text
|
|
include "NSLog.incl"
|
||
|
|
|
||
|
|
local fn RepeatingStrings
|
||
|
|
NSUInteger i
|
||
|
|
CFArrayRef testCases = @[@"1001110011", @"1110111011", @"0010010010", @"1010101010",
|
||
|
|
@"1111111111", @"0100101101", @"0100100", @"101", @"11", @"00", @"1"]
|
||
|
|
|
||
|
|
for CFStringRef string in testCases
|
||
|
|
NSUInteger length = len(string)
|
||
|
|
CFMutableArrayRef repeats = fn MutableArrayNew
|
||
|
|
|
||
|
|
for NSUInteger prefixLen = 1 to length / 2
|
||
|
|
BOOL repeatsPrefix = YES
|
||
|
|
|
||
|
|
for i = prefixLen to length - 1
|
||
|
|
if ( fn StringCharacterAtIndex( string, i ) != fn StringCharacterAtIndex( string, (i % prefixLen) ) )
|
||
|
|
repeatsPrefix = NO
|
||
|
|
break
|
||
|
|
end if
|
||
|
|
next
|
||
|
|
|
||
|
|
if ( repeatsPrefix )
|
||
|
|
MutableArrayAddObject( repeats, fn StringSubstringToIndex( string, prefixLen ) )
|
||
|
|
end if
|
||
|
|
next
|
||
|
|
|
||
|
|
CFStringRef outputStr
|
||
|
|
if ( fn ArrayCount(repeats) > 0 )
|
||
|
|
outputStr = fn ArrayComponentsJoinedByString( repeats, @", " )
|
||
|
|
outputStr = fn StringByTrimmingCharactersInSet( outputStr, fn CharacterSetWhitespaceSet )
|
||
|
|
else
|
||
|
|
outputStr = @"(no repeat)"
|
||
|
|
end if
|
||
|
|
NSLog( @"%10s : %@", fn StringUTF8String(string), outputStr )
|
||
|
|
next
|
||
|
|
end fn
|
||
|
|
|
||
|
|
fn RepeatingStrings
|
||
|
|
|
||
|
|
HandleEvents
|