Answer the question
In order to leave comments, you need to log in
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
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.
majestik : This is an IT portal, not a school math help.
Divide the larger by the smaller with rounding.
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 questionAsk a Question
731 491 924 answers to any question