1. ## Page number problem

Hi,

I have an interesting problem hopefully some bright spark might be able to solve:

I am developing automated report showing four photos per page. Each photo is numbered 1,2,3 etc. Using the page number (call this Z) it needs to work out, in order, which photos to choose out of the list.
There needs to be four seperate equations (one for each of the photo blocks) to choose the number of photo needed.
I.e. Page 1 has photos 1,2,3,4. Page 2 has photos 5,6,7,8 etc..

An example for two photos per page would be:
Top photo block calc = ((Z-1)*2)+1
Bottom photo blocl calc = Z*2

For four photo blocks however just gets a bit too much for me to work out!

Any help?....

2. ## Re: Page number problem

Hey hamishm.

I'm a little confused on what you are asking.

For each photo block, what kind of rule are you using to select the number of photos? What do the four equations refer to? Can you write them down or explain the four equations in sufficient detail?

What is the basic idea you are using to select a photo given the past photos selected for past blocks? What are the details of the configuration of each block?

3. ## Re: Page number problem

Sorry if it is a bit unclear.
The four equations are unknown and what I am hoping someone will be able to work out.
Picture this:
On one page there is four photo blocks (one after the other going vertically down the page). Each of these will have a photo. The photos need to be presented in sequential order and are numbered in sequence in a database with a filepathname associated with it. To select the appropriate photo the photo block needs to know the right number in sequence. These blocks are completely independant of one another.

The result would be Page 1 has photos 1,2,3,4. Page 2 has photos 5,6,7,8 and the photo numbers would be chosen by the equation in each block.

Knowns in the problem:
1. The page number
2. What photo block is what. I.e is it the top, bottom or one of the two middle blocks
The unknown:
1. What photo sequence number to use. Presumably this would be solved using math and basic true false type functions. One equation for each photo block.

For a simple page with two blocks. To idendify the sequence number we would use
Top photo block calc = ((Page Number-1)*2)+1
Bottom photo blocl calc = PageNumber*2

4. ## Re: Page number problem

Basically it sounds like a radix problem.

Can you tell me what the minimum and maximum values are for all your variables? If all but one are fixed, the formula is a very easy based on the radix representation and DIV/MOD algorithm to recover all of the variables.

If you have more than one unrestricted variable, then you will probably have to choose a range that is big enough and use that instead.

5. ## Re: Page number problem

Hi,

There is 50 photos maximum at this stage. The photo sequence numbers would be 1-50. So 13 pages with four photos on each except the last page which would have two photo.
Does that help?

6. ## Re: Page number problem

If you have a photos per block (maximum), b blocks per page (maximum) then the number for that particular photo given page x, block y, and photo z will be:

number = x*(a*b) + y*b + z where 0 <= z < b - 1, and 0 <= y < a-1 (all are whole positive numbers).

To get back the information you do the following:

n = number % b (n = z after this operation)
n = n \ b (integer division)
n = n % a (n = y after this operation)
n = n \ a (integer division)
n = x after the above operation.

So given number, you can recover x,y,z using the DIV/MOD algorithm (shown above for this special case) and you can create a number given the formula above.

Note that things start at 0 instead of 1 and go to a-1 and b-1 instead of a and b.