Understanding clones

Hey everyone!

I'm new to programming and just trying to wrap my head around lists and clone data.

My task is to gather x-position data from all clones created (user integer input creates number of clones) and find the 2 closest clones relative to their x-position, and present that information in a list. The y-position of all clones is locked and irrelevant.

I am struggling with comparing all the x-position data to find the closest pair.

Any help is greatly appreciated

Welcome to Snap! and to the forum!

So, instead of making the n² comparisons of every position to every other position, I would sort the clones by x position, and then you can just compare the differences between adjacent ones. (That wouldn't work if you were comparing distances in two dimensions, but you're not.)

Is this a homework problem? The otherwise strange irrelevance of the y position sounds like a teacher trying to make the problem easy for you. I ask because I don't know what the rules are, e.g., whether I can point you to the library procedure that sorts lists.

Yes, it is a homework problem!

The main requirement is to use a sense reporting block and program that to produce the list of the 2 closest pairs.

Do you think nesting "for loops" of the lists is a reasonable way?

You could do it that way. I would still sort the list, but you should do what you know how to do!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.