Best shuffle: Difference between revisions
Content added Content deleted
m (Edited examples) |
mNo edit summary |
||
Line 2,004: | Line 2,004: | ||
local fn ShuffleString( string as CFStringRef ) as CFStringRef |
local fn ShuffleString( string as CFStringRef ) as CFStringRef |
||
'~'1 |
|||
NSInteger i |
NSInteger i |
||
Line 2,016: | Line 2,015: | ||
local fn StringDifferences( string1 as CFStringRef, string2 as CFStringRef ) as NSInteger |
local fn StringDifferences( string1 as CFStringRef, string2 as CFStringRef ) as NSInteger |
||
⚫ | |||
'~'1 |
|||
⚫ | |||
if fn StringLength( string1 ) != fn StringLength( string2 ) then NSLog( @"Strings must be of equal length." ) : exit fn |
if fn StringLength( string1 ) != fn StringLength( string2 ) then NSLog( @"Strings must be of equal length." ) : exit fn |
||
Line 2,024: | Line 2,022: | ||
CFStringRef tempStr1 = fn StringSubstringWithRange( string1, fn CFRangeMake( i, 1 ) ) |
CFStringRef tempStr1 = fn StringSubstringWithRange( string1, fn CFRangeMake( i, 1 ) ) |
||
CFStringRef tempStr2 = fn StringSubstringWithRange( string2, fn CFRangeMake( i, 1 ) ) |
CFStringRef tempStr2 = fn StringSubstringWithRange( string2, fn CFRangeMake( i, 1 ) ) |
||
if fn StringIsEqual( tempStr1, tempStr2 ) == YES then |
if fn StringIsEqual( tempStr1, tempStr2 ) == YES then unchangedPosition++ |
||
next |
next |
||
end fn = |
end fn = unchangedPosition |
||
NSInteger i, j, count |
NSInteger i, j, count |
||
Line 2,046: | Line 2,044: | ||
HandleEvents |
HandleEvents |
||
</lang> |
</lang> |
||
Output with four shuffles |
Output with four shuffles: |
||
<pre> |
<pre> |
||
abracadabra, caaarrdabab, (4) |
abracadabra, caaarrdabab, (4) |