math - PHP Formula For a Series of Numbers (Mathy Problem) -
my apologies if wrong site problem, more math-related programming.
i trying write series of 7 page links, in google-esque fashion. essentially, 7 numbers, s (s + 6), s starting value. having trouble calculating starting value, given limited amount of information.
in advance, know maximum value in series, variable, greater 7. in formula-writing attempts, have been calling value g, g > 7.
i know page number user has selected. have been calling value p
so, example, if g 8, need generate these series of numbers, bolded number equal p:
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
2 3 4 5 6 7 8
2 3 4 5 6 7 8
2 3 4 5 6 7 8
2 3 4 5 6 7 8
as long can determine starting value using information available, else falls place. can advise on how calculate starting value using information available? if relevant, writing formula in php.
thanks in advance input.
this simulation code testing.
<? $g=16; for($p=1;$p<17;$p++){ $start = $g-$p > 3 ? ($p-4<1?1:($p-4)) : $g-6; echo "$p :: "; for($i=$start;$i<$start+7;$i++){ echo $i . " "; } echo "<br>"; } ?>
so start page decided (the thing need):
$start = $g-$p > 3 ? ($p-4<1?1:($p-4)) : $g-6;
output (simulation g=16, , p 1 16)::
p :: page numbers
1 :: 1 2 3 4 5 6 7 2 :: 1 2 3 4 5 6 7 3 :: 1 2 3 4 5 6 7 4 :: 1 2 3 4 5 6 7 5 :: 1 2 3 4 5 6 7 6 :: 2 3 4 5 6 7 8 7 :: 3 4 5 6 7 8 9 8 :: 4 5 6 7 8 9 10 9 :: 5 6 7 8 9 10 11 10 :: 6 7 8 9 10 11 12 11 :: 7 8 9 10 11 12 13 12 :: 8 9 10 11 12 13 14 13 :: 10 11 12 13 14 15 16 14 :: 10 11 12 13 14 15 16 15 :: 10 11 12 13 14 15 16 16 :: 10 11 12 13 14 15 16
and simulation g=8, p 1 8
1 :: 1 2 3 4 5 6 7 2 :: 1 2 3 4 5 6 7 3 :: 1 2 3 4 5 6 7 4 :: 1 2 3 4 5 6 7 5 :: 2 3 4 5 6 7 8 6 :: 2 3 4 5 6 7 8 7 :: 2 3 4 5 6 7 8 8 :: 2 3 4 5 6 7 8
Comments
Post a Comment