Problem: We have x checkboxes and we want to check y of them evenly.
Example 1: select 50 checkboxes of 100 total.
[-]
[x]
[-]
[x]
...
Example 2: select 33 checkboxes of 100 total.
[-]
[-]
[x]
[-]
[-]
[x]
...
Example 3: select 66 checkboxes of 100 total:
[-]
[x]
[x]
[-]
[x]
[x]
...
But we're having trouble to come up with a formula to check them in code, especially once you go 11/111 or something similar. Anyone has an idea?
In algebra and number theory, a distribution is a function on a system of finite sets into an abelian group which is analogous to an integral: it is thus the algebraic analogue of a distribution in the sense of generalised function.
Definition: Distribution means to spread the product throughout the marketplace such that a large number of people can buy it.
Benford's law (also called the first digit law) states that the leading digits in a collection of data sets are probably going to be small. For example, most numbers in a set (about 30%) will have a leading digit of 1, when the expected probability is 11.1% (i.e. one out of nine digits).
Benford's Law holds true for a data set that grows exponentially (e.g., doubles, then doubles again in the same time span), but also appears to hold true for many cases in which an exponential growth pattern is not obvious (e.g., constant growth each month in the number of accounting transactions for a particular cycle ...
Let's first assume y
is divisible by x
. Then we denote p = y/x
and the solution is simple. Go through the list, every p
elements, mark 1 of them.
Now, let's say r = y%x
is non zero. Still p = y/x
where /
is integer devision. So, you need to:
p-r
elements, mark 1 elementsr
elements, mark 2 elementsNote: This depends on how you define evenly distributed. You might want to spread the r
sections withx+1
elements in between p-r
sections with x
elements, which indeed is again the same problem and could be solved recursively.
Alright so it wasn't actually correct. I think this would do though:
Regardless of divisibility:
y > 2*x
, then mark 1 element every p = y/x
elements, x
times.y < 2*x
, then mark all, and do the previous step unmarking y-x
out of y
checkboxes (so like in the previous case, but x
is replaced by y-x
)Note: This depends on how you define evenly distributed. You might want to change between p
and p+1
elements for example to distribute them better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With