Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Best-shuffle/FutureBasic/best-shuffle.basic
Normal file
43
Task/Best-shuffle/FutureBasic/best-shuffle.basic
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
include "Tlbx GameplayKit.incl"
|
||||
include "NSLog.incl"
|
||||
|
||||
local fn ShuffleString( string as CFStringRef ) as CFStringRef
|
||||
NSInteger i
|
||||
|
||||
CFMutableArrayRef mutArr = fn MutableArrayWithCapacity( 0 )
|
||||
for i = 0 to fn StringLength( string ) - 1
|
||||
MutableArrayAddObject( mutArr, fn StringSubstringWithRange( string, fn CFRangeMake( i, 1 ) ) )
|
||||
next
|
||||
CFArrayRef shuffledArr = fn GKRandomSourceArrayByShufflingObjectsInArray( fn GKRandomSourceInit, mutArr )
|
||||
end fn = fn ArrayComponentsJoinedByString( shuffledArr, @"" )
|
||||
|
||||
|
||||
local fn StringDifferences( string1 as CFStringRef, string2 as CFStringRef ) as NSInteger
|
||||
NSInteger i, unchangedPosition = 0
|
||||
|
||||
if fn StringLength( string1 ) != fn StringLength( string2 ) then NSLog( @"Strings must be of equal length." ) : exit fn
|
||||
|
||||
for i = 0 to fn StringLength( string1 ) -1
|
||||
CFStringRef tempStr1 = fn StringSubstringWithRange( string1, fn CFRangeMake( i, 1 ) )
|
||||
CFStringRef tempStr2 = fn StringSubstringWithRange( string2, fn CFRangeMake( i, 1 ) )
|
||||
if fn StringIsEqual( tempStr1, tempStr2 ) == YES then unchangedPosition++
|
||||
next
|
||||
end fn = unchangedPosition
|
||||
|
||||
NSInteger i, j, count
|
||||
CFArrayRef stringArr
|
||||
CFStringRef originalStr, shuffledStr
|
||||
|
||||
stringArr = @[@"abracadabra", @"seesaw", @"elk", @"grrrrrr", @"up", @"a"]
|
||||
count = fn ArrayCount( stringArr )
|
||||
|
||||
for i = 0 to 3
|
||||
for j = 0 to count - 1
|
||||
originalStr = stringArr[j]
|
||||
shuffledStr = fn ShuffleString( stringArr[j] )
|
||||
NSLog( @"%@, %@, (%ld)", originalStr, shuffledStr, fn StringDifferences( originalStr, shuffledStr ) )
|
||||
next
|
||||
NSLog( @"\n" )
|
||||
next
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue