My apologies if this is the wrong site for this problem, as it is more math-related than programming.I am trying to write a series of 7 page links, in a Google-esque fashion. Essentially, it will be 7 numbers, where s is my starting value. I am having trouble calculating my starting value.
In advance, the maximum value in the series is variable depending on the search terms provided by the user, it could be less than, greater than or equal to 7. In my formula-writing attempts, I have been calling this value g. I also know the page number the user has selected. I have been calling this value p So, for example, if g was 21, I would need to generate these series of numbers, where the bolded number is equal to 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
4 5 6 7 8 9 10
5 6 7 8 9 10 11
15 16 17 18 19 20 21
As long as I can determine the starting value using the information available, everything else falls into place. Can anyone advise on how I would calculate my starting value using the information available? If it is relevant, I will be writing this formula in PHP.
Suppose you want
$nlinks and$gis the number of pages, in your case$n = 7, the the starting value$scan only range from1to$g - ($n - 1).In general, when you are not outside these limits the starting value
$sis related to the page number by$s = $p - floor($n / 2).Putting all this together into a PHP function you get:
You can test this function as follows:
This will print the start pages of example sequences you gave in your question.