0

I have graves in a churchyard organized in rectangular grids. Each grave has an id number and I want to calculate the column and row position of the grave. For each section of the churchyard I know:

  1. The id of the grave I want to locate.
  2. The id of the bottom left grave in the grid.
  3. The amount the id of the grave increases as you move along rows from grave to grave (normally 1 or -1)
  4. The amount the id of a grave increases as you move back from one row to the next (often a negative number, if the front row of graves has the highest ids numbers of the section).

Once I know the row number I can calculate the column, but what formula can I use to calculate the column? For example:

702 703 704
712 713 714
722 723 724
732 733 734

So, I know the grave I want is 724, that the bottom left grave is 732, and that grave ids increase by 1 along the row and by -10 from row to row. How do I arrive at the row number "2" mathematically?

I have tried calculating the difference between the two grave ids (724-732=-8) and then dividing by the row difference (-8/-10 = 0.8) but that does not give me the right answer.

I also tried rounding up and adding 1 (to convert from row index to row number) but this does not work when the number difference between rows is a positive number e.g. (714-702)/10=1.2, so I need to round down in that case.

It's almost like I need to round down when the row difference is positive and up when it's negative.

1 Answers1

1

If you know the ID of the first grave in the last row and the number of graves in a row, you can find the max ID. In your example, it's bottom right, #$734$. The formula you can use to calculate row number is $1+\lfloor\frac{734-\text{grave id}}{\text{number by which id changes from row to row}}\rfloor$ (using the floor function)

Vasili
  • 10,690