Hi there, I am having trouble sorting some data and I am not sure if there is a way to do this with components or if it needs a script. I am a very basic coder so if it does need scripting I would really appreciate a very basic description.
Anyways, I have a set of numbers in a panel - 191, 336, 485, 392, 757, 191. these numbers need to be divided up into even groups of numbers 3-10. so for example 191 can be divided up evenly 3 times with 35 left over. now I want to divide 35 amongst the groups numbers which is what is causing the issue because I want it to be automated so I can change 191 to any number and it will sort this. Please any help will be appreciated!
I’m not really sure what you’re trying to do. 191 is 52*3 + 35, but why not 63*3 + 2? I’m also not sure what “divide 35 amongst the groups numbers” means. Can you be more clear what output you want or provide a worked example case?
Hi @Measure Thank you for replying! Sorry the question was unclear I have been working on this for 2 days and posted in an unclear frustration of just wanting a solution…
Let me clarify:
I am making planting plans (Landscape Architect) I have 191 plants that i will be planting in groups of 3-10 plants (which will be represented as circles, I already have that code I just have this number sorting issue to work out). I want my plants to be as evenly distributed among the groups as possible. So as per the example that means 191/52 = 3 meaning I have 3 groups of 3, 4, 5, … etc.
because 191= 52*3 + 35 I need to solve for how to distribute the remaining 35 plants into my groupings of 3-10. For example 35 can be divided up into 1 group of 10, 1 group of 9 and 2 groups or 8, or in many other combinations however because I want an equal (or as equal as possible) distribution then I would prefer to have only 1 or 2 additional groups of each number.
I imagine a code to run as follows, but am having a hard time constructing it myself:
Where X<52 and it needs to be sorted into groups of 3-10 I would like it to run (if this makes the most sense)
a-10 = b
if b>3 then solve for:
b-9 = c
if c<3 then solve for:
9+c and stop there
if c>3 then solve for
c-8 = d
if d<3 then solve for:
8+d and stop there
and so on…
and then to make this even more complicated the list i would like it to put out is 10, 9, 8 8 not 25, 16, 8, 8
Hopefully this is maybe clearer, and again thank you for the help!!!
UPPER = 10
LOWER = 3
def split(remainder):
output = []
for i in range(UPPER, LOWER-1, -1):
if remainder-i >= LOWER:
output += [i]
remainder -= i
elif remainder > UPPER:
output += [remainder-LOWER, LOWER]
break
else:
output += [remainder]
break
return output
for i in range(52):
print(i, split(i))
There might be some special cases if, for example, your starting number is something like 53 which this would split into a full set of 3-10 with only 1 left over that doesn’t fit into any of your allowed group sizes.