Optimization solver for staggered pattern

hello guys, i have robotic fabrication concept in mind, for which i first need to develop the algorithm. I am not good in gh, so I would highly appreciate if you give me any sort of advice on this point.

The heart of the concept is a algorithm that needs to detect the suitable element from the list based on parameters. The first input would be a big list of random lengthes of lines. The second input is a span. The loop through the list starts when the element needs to be placed (s. sketch, in red) The algorithm searches for the element that has more or less the same length as the desirable length. This desirable length (D) is everytime dynamic variable - the end point of D is a middle point of the neighbour element in a previous row. The result of the whole is kind of “staggered” pattern.

Would you say this is more managable in galapagos, or maybe python? Or something else!

Again, thank you so much in advance if you can share your thoughts about this issue.