M
M
majestik2015-12-12 03:35:25
PHP
majestik, 2015-12-12 03:35:25

How to implement uniform distribution?

How to implement uniform distribution?
For example, I have 11 apples, I need to evenly distribute them in order to eat within 30 days.
If it were 30/30 => an apple a day, if 11/30 ≈ an apple in 3 days. How to implement this in php for n-apples and n-days? Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew, 2015-12-12
@majestik

Divide m by n in real numbers.
Then every day add the indicated real fraction to some real counter and output the difference between rounding down between today and yesterday - this is your integer norm for today. You can round to the nearest integer - in principle, it does not matter - as long as it is monotonous all the time.

S
Saboteur, 2015-12-12
@saboteur_kiev

majestik : This is an IT portal, not a school math help.
Divide the larger by the smaller with rounding.

I
Immortal_pony, 2015-12-12
@Immortal_pony

function printApplesPerDays($apples, $days) {
    echo "I can eat " . number_format($apples/$days, 1) . " apples per day"; 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question