Confusing Math Problem
Posted: Mon Jan 19, 2009 2:29 pm
You have a summary gadget on a web page. Its goal is not to show the whole set of results, just some of those results. One then clicks View All and see the rest. So, there are 3 variables:
$a - # of active accounts in the system
$e - # of expired accounts in the system
$T - # specified in a conf file on how many items to show in the summary gadget
Each of these are known and you pass it to a function like:
function DisplaySummary($a, $e, $T)
The goal is to show as many active accounts as you can and as many expired accounts as you can, but no more than the value of $T for both of them together. So, in general, var $a should not be > ceil($T/2). But if var $a <= ceil($T/2), then give preference to var $e. You also have to take into account rounding, so if $T is 9, which does not divide evenly, then give preference to either var $a or var $e, whichever is >= ceil($T/2).
So, I'm trying to figure out the if/then logic.
$a - # of active accounts in the system
$e - # of expired accounts in the system
$T - # specified in a conf file on how many items to show in the summary gadget
Each of these are known and you pass it to a function like:
function DisplaySummary($a, $e, $T)
The goal is to show as many active accounts as you can and as many expired accounts as you can, but no more than the value of $T for both of them together. So, in general, var $a should not be > ceil($T/2). But if var $a <= ceil($T/2), then give preference to var $e. You also have to take into account rounding, so if $T is 9, which does not divide evenly, then give preference to either var $a or var $e, whichever is >= ceil($T/2).
So, I'm trying to figure out the if/then logic.