Hi, this issue baffles and annoys me quite a bit. The issue is with the block on the right. Here's what its meant to do:
The sprite creates as many clones as inputed through "alonzo count". The clones are then randomly spread along y=-160. The reporter block on the left creates a list of the distances between the clones. All the functions up until now happen instantly, no lags at all. However, the reporter block on the right gives me headaches. It's function is to find the smallest non-zero number in the generated list. The list has positive and negative values, the first item in the list is zero, and there are a few other zeros in the list. The block then reports the position of the smallest number on the list.
As the number of clones increases, the list generated by the first block increases by (nubmer of clones)^2. Each increase in number of clones makes the second block exponentially slower. The warp block doesn't seem to help with this.
In the second block Clone with smallest distance, make another script variable (Assume you will call it data) and set that to the 1st reporter block you mentioned distance between each clone and replace all duplicated instances of distance between each clone block with the script variable you declared the distance between each clone (Data script variable in this solution). Hope this helps! If this does not speed up the clone with smaller distance block, then I can't find another one.
@hm100 is right about the main problem, namely calling DISTANCE BETWEEN EACH BLOCK six times for every item of the list that the first call returns. That's where the exponential growth in time comes from.
I'd like to add a couple of stylistic points. First, instead of computing √̅x̅²̅ to get the absolute value, there's an ABS option in the pulldown menu of the SQRT block.
More importantly, the most Snap!ish way to do this computation, probably also the fastest, is to use higher order functions and hyperblocks:
≠ and MIN are hidden primitives; to find them, grab an = and a MOD block, respectively, right-click it, and choose RELABEL from the menu. (Or just write them in Snap! yourself.)
I implemented the suggestions on the operators reporter block named "clone with smallest distance 2".
All the commands work with "clone with smallest distance" but the block is slow. The block "distance between each clone" generates the list used by these blocks.
Ideally, I need a block that gives the exact output as "clone with smallest distance" as the whole project is reliant on that block. But I need it to be fast.
Higher order functions (map, keep, find first, combine) work by filling empty slots in the expression inside the gray ring, repeatedly, once for each item of the input list. So
In this case two different values go into the two empty input slots of each × block.
COMBINE USING MIN would find the smallest value in a list of numbers. But in your problem you have a list of index-value pairs, so the combining function is a little more complicated.
But on top of that, as I'm writing this I see that the function should be