37 lines
864 B
Plaintext
37 lines
864 B
Plaintext
include "NSLog.incl"
|
|
|
|
local fn LookAndSay( testWord as CFStringRef ) as CFStringRef
|
|
NSUInteger i, length, times
|
|
CFMutableStringRef result = fn MutableStringWithCapacity(0)
|
|
|
|
unichar repeat = fn StringCharacterAtIndex( testWord, 0 )
|
|
times = 1
|
|
testWord = fn StringWithFormat( @"%@ ", fn StringSubstringFromIndex( testWord, 1 ) )
|
|
length = len(testWord)
|
|
|
|
for i = 0 to length - 1
|
|
unichar actual = fn StringCharacterAtIndex( testWord, i )
|
|
if ( actual != repeat )
|
|
MutableStringAppendFormat( result, @"%d%c", times, repeat )
|
|
times = 1
|
|
repeat = actual
|
|
else
|
|
times++
|
|
end if
|
|
next
|
|
end fn = fn StringWithString( result )
|
|
|
|
void local fn DoIt
|
|
NSUInteger i
|
|
CFStringRef numStr = @"1"
|
|
|
|
for i = 1 to i <= 15
|
|
NSLog( @"%@", numStr )
|
|
numStr = fn LookAndSay( numStr )
|
|
next
|
|
end fn
|
|
|
|
fn DoIt
|
|
|
|
HandleEvents
|