Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to make something like this to my variable data value...

$maxvalue = 0;
$basevalue = 0;
if($basevalue == 0) {$maxvalue = 0;}
else if ($basevalue == 1) {$maxvalue = 884;}
else if ($basevalue == 2) {$maxvalue = 1819;}
else if ($basevalue == 3) {$maxvalue = 2839;}

and so on.. i believe there is no exact computation on how the $maxvalue shifts as the basevalue increase. Can someone suggest me a simplier way to do this? thanks in advance!

share|improve this question
Do you have more values? Maybe there is a pattern. – GolezTrol yesterday
im not sure.. its really weird. here's 1-10 values.. 1-884, 2-1819, 3-2839, 4-3978, 5-5270, 6-6749, 7-8449, 8-10404, 9-12648, 10-15215 ... the fact that its until 100.. lol – Gelo103097 yesterday
so still no luck getting the pattern? =_= – Gelo103097 yesterday
As a matter of fact I do. – GolezTrol yesterday

2 Answers

up vote 6 down vote accepted
$maxvalues = array(0, 884, 1819, 2839, ...);
$maxvalue  = $maxvalues[$basevalue];
share|improve this answer

It looks like there's a pattern, almost like a faculty, but also with some other calculations. All numbers are multiples of 17. The following function returns the numbers you provided, so I think it might work for the higher numbers too:

function getMaxValue($base)
{
    // Factor of $base = 51 + $base^2 + Factor($base - 1). You
    // could solve that in a recursion, but a loop is generally better.
    $factor = 0;
    for ($i = 1; $i <= $base; $i++)
      $factor += 51 + ($i * $i);
    return $factor * 17;
}

// Test
for ($i = 0; $i < 100; $i++)
{
    echo "$i -- " . getMaxValue($i) . "<br>\n";
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.