Actionscript 2: Hittest on multiple MCs - actionscript

I am running a hittest on an array of thousands of MCs a little a part, due to the nature of this sometimes two can be hit at once.
How would I narrow it down so that the one which is hit the most is the one returned value?

Have a specific variable increment each time a specific movieclip is hit.
Place all of these variables in an array.
sortOn the array for DESCENDING order.
select the first element in the array (myArray[0]), as that will have the highest value

Related

What's the best way of finding the highest value of a table, that is inside a table?

The title is somewhat self-explanatory. I have a table containing a lot of smaller tables with two integers. I need to find the highest/lowest value of the first and second integer within those sub-tables and then output the entire sub-table with the highest/lowest number.
The only way I can come up with seems fairly unintuitive and expensive.
If you need Lua to do the work for you, you can use table.sort and pass it your own sorting function that will sort based on the values of first/second integer and then pick first/last element from the sorted table. If you can maintain the sorted order when inserting (using binary search for a position), then you can always pick the first/last element as needed.

How to exchange TList items during a for-loop

I have a TList which' items are continuously processed by many for-loops. I sometimes need to exchange items in the list in order to rearrange the order of the visual representation of the list (in a StringGrid).
How do I exchange these items?
My preliminary thoughts are:
During the for-loop I think the items should not be exchanged.
If I do the exchange in a Timers' OnTimer event, having set the Timers' interval to a very short interval (e.g. 1 millisecond), then I think the for-loop will have only an intermission of that one millisecond.
Will this work? Or are there better alternatives?
As long as you ensure that the count of the items in a TList does not change, exchanging items is perfectly fine during a for-loop. Note that, depending on the index of the items that are about to be exchanged, some of the items may not be processed or may be processed twice.
If the exchange operation is not called from within the for-loop, then an already started for-loop will run until it is done. You cannot expect to "break in" with a Timer, because that Timer's message will not be processed until the for-loop and all surrounding code is done.
So, the solution for your problem could be:
exchange the items within the for-loop,
use a threading solution to be able to do two different things simultaniously on one list (this may need some learning about threads),
wait until the for-loop is done, and exchange then,
split the for-loop in multiple slices to reduce the time needed, or
use a timer to start multiple for-loops in order to give your program some breathing time in between.

linked list biggest number

I am trying to retrieve the biggest number in a Linked List containing only integers.
If the list contains: 2, 67, 3, 9.
I want to return 67.
I'm having trouble visualizing and coming up with code that does this. Even a pseudo code would help.
Edit: I'm using Java to do this.
Note that:
You need to traverse the whole list; you don't know in advance where the maximum is going to be.
You'll need to carry some state while traversing: at any point, it may be the case that the rest of the list does not contain the maximum, and so you'll need to hang on to your current understanding of what it is.
So the general form of the pseudo-code will look like this:
Initialise the state that represents the maximum.
For each element in the list in turn: update the state, based on the element.
Lastly, you'll need to handle the edge cases: what does it mean to find the maximum of an empty Linked List?
To be more specific:
If the list is empty, return an error condition.
Let m, representing the current idea of the maximum, be the first element of the list.
For each remaining element of the list, if it is greater than m, set m to be the element.
At each point in the iteration, you have the invariant that m is the largest number so far in the list. When you are done, it must therefore be the largest number in the whole list.

SUMIFS Values from non consecutive Column Cells

I need tu sum several cells that are separated one from another, these cells are
C3,F3,I3,L3,O3,R3,U3,X3,AA3,AD3,AG3,AJ3,AM3,AP3,AS3,AV3,AY3,BB3,BE3,BH3,BK3,BN3,BQ3,BT3,BW3,BZ3,CC3,CF3,CI3,CL3,CO3
if this other cells $C$1,$F$1,$I$1,$L$1,$O$1,$R$1,$U$1,$X$1,$AA$1,$AD$1,$AG$1,$AJ$1,$AM$1,$AP$1,$AS$1,$AV$1,$AY$1,$BB$1,$BE$1,$BH$1,$BK$1,$BN$1,$BQ$1,$BT$1,$BW$1,$BZ$1,$CC$1,$CF$1,$CI$1,$CL$1,$CO$1
that are on the same column but different row are >= to certain number given and <= to other given number, but it returns #Value, can somebody help me find out what am I doing wrong?
This is the function i am writing:
=SUMIFS((C3,F3,I3,L3,O3,R3,U3,X3,AA3,AD3,AG3,AJ3,AM3,AP3,AS3,AV3,AY3,BB3,BE3,BH3,BK3,BN3,BQ3,BT3,BW3,BZ3,CC3,CF3,CI3,CL3,CO3),($C$1,$F$1,$I$1,$L$1,$O$1,$R$1,$U$1,$X$1,$AA$1,$AD$1,$AG$1,$AJ$1,$AM$1,$AP$1,$AS$1,$AV$1,$AY$1,$BB$1,$BE$1,$BH$1,$BK$1,$BN$1,$BQ$1,$BT$1,$BW$1,$BZ$1,$CC$1,$CF$1,$CI$1,$CL$1,$CO$1),">="&B55,($C$1,$F$1,$I$1,$L$1,$O$1,$R$1,$U$1,$X$1,$AA$1,$AD$1,$AG$1,$AJ$1,$AM$1,$AP$1,$AS$1,$AV$1,$AY$1,$BB$1,$BE$1,$BH$1,$BK$1,$BN$1,$BQ$1,$BT$1,$BW$1,$BZ$1,$CC$1,$CF$1,$CI$1,$CL$1,$CO$1),"<="&C55)
I'm not 100% certain, but it looks like the problem here is that SUMIFS requires arguments to be expressed in continuous-range form, e.g. A3:CO3. It looks like you're trying to work with every third column in the dataset, yes? As far as I can tell, this is best (only?) done as an array function, so that you can tell it to filter on "every third column."
Enter this in the cell, then press CTRL+SHIFT+Enter (CSE) to evaluate it as an array function:
=SUM(($A$1:$CO$1>=B55)*($A$1:$CO$1<=C55)*(MOD(COLUMN(A3:CO3),3)=0)*(A3:CO3))
You'll also need to hit CSE every time you evaluate or change it. There's a decent tutorial for array functions at https://support.office.com/en-za/article/Guidelines-and-examples-of-array-formulas-7d94a64e-3ff3-4686-9372-ecfd5caa57c7, which may help if you're unfamiliar with them.

save coordinates for graph in table and then remove them in random order? best approach to do this?

I have a situation and it goes like this:
I need to print out coordinates like the one's used in a maths graph. So (0,0) (0,1) (0,2) and so on. So if the length is specified as 10 and breadth is specified as 20 then the graph region will be all the points from (0,0) till (10,20).
I wish to store these values in a table so that these can be printed out in order.
Later on, there is a scenario that some of these values will get removed so suppose the values removed are (4,5) (4,6) (4,7) and then the main table that was created earlier should not contain these values. And I need to be able to print out the new table with the remaining values.
Till now I have only done the coding to ask for the length and the breadth values.
How should I go ahead with the rest of this?
In case you need any clarification or the question if too confusing then please leave a comment and I will try to make it better.
Any help will be very highly appreciated.
Thank you
There are a few ways of doing this depending on what you want.
The easy way is to use an array of arrays like this:
a = Array.new(11) {Array.new(21) {0}}
This creates an array like a[0][0] to a[10][20], with every item initialized to 0.
To remove an item, set it to nil:
a[4][5] = nil
When you print the array, skip any nil values:
for x in 0..10
for y in 0..20
next if a[x][y]==nil
puts a[x][y]
end
end
If your graph is very large, read about a "sparse matrix" which is how tools like Excel store many cells using less RAM for blank cells:
http://en.wikipedia.org/wiki/Sparse_matrix

Resources