Distributing rectangle panels along the curve (and possible use of attractors)

Thank you @inno for coming up with a great solution for my last question! I wonder if you might be able to suggest a solutions this time as well? (or anyone else on this forum):

I’d like to distribute curves (or boxes, it doesn’t matter) along another curve.

Let’s imagine my curve is 8640mm long (it will change every time so being able to connect rhino curve or type length would be fab). I can distribute either 16 no boxes, each one of them 540mm wide OR I can have 13 no. boxes 580mm wide + 2 no boxes 550mm wide. This way I ‘utilised’ the curve fully, and have no gaps between the boxes, and no gaps at the ends. Perfect.

Is there a way to give Grasshopper the curve so then the grasshopper would figure different combinations of these box arrangements in such way to have either no gaps at the ends (like I did above), or just tiny minimal gaps at the ends (there will be never any gaps in between the boxes). A slider so I could play with the results would be cool, but the main thing is so the Grasshopper would be only allowed to create combinations based on the 3 widths: either 530 / 540 / 550mm OR 540 / 550 / 560mm. (But the less boxes the better! So if that length can be achieved with only 1 width - eg. 16 @ 540 - that’s great).

At the moment I’m just trying to figure out how to do it in a straight line, in the future I’d love to be able to distribute these boxes along arching curves as well. I’m using Rhino 6 if it makes any difference.

Any help would be much appreciated!