repeat with m = 1 to 100000
I've heard that "repeat for each" is faster, but I don't know how I would use that here.
Code: Select all
on mouseUp
#input original array
put specialFolderPath("documents") & "/IntegerArray.txt" into tFilePath
put url ("file:" & tFilePath) into tArray
#this is the smaller list that worked fine
-- put "9,10,8,1,4,7,6,2,5,3" into tBeg
-- set itemdelimiter to comma
-- repeat with i=1 to 10
-- put item i of tBeg & cr after tArray
-- end repeat
put 1 into i
put 1 into j
put tArray into t1
repeat with tWhole = 2 to 131072--groups from 2 to n
put tWhole/2 into tHalf
repeat with m = 1 to 100000--each level
if tHalf=1 then
put line m of t1 into tLeft
put line m+1 of t1 into tRight
else
put line m to m+tHalf-1 of t1 into tLeft
put line m+tHalf to m+tWhole-1 of t1 into tRight
end if
repeat with k = 1 to tWhole--each run
if line j of tRight = empty or\
i<tHalf+1 and\
line i of tLeft < line j of tRight or\
j>tHalf then
put line i of tLeft & cr after t2
add 1 to i
else
put line j of tRight & cr after t2
add 1 to j
if i<tHalf+1 then
add tHalf - i + 1 to tInv
end if
end if
end repeat
put 1 into i
put 1 into j
add tWhole-1 to m
end repeat
put tWhole*2-1 into tWhole
put t2 into t1
put empty into t2
end repeat
put tInv into field 11
end mouseUp