Get pair number of given shelf number

45 Views Asked by At

I work at a warehouse, and have shelves organized in that way:

(number means shelf number and "--" means aisle between shelves)

1    2
--  --
3    4 
5    6
--  --
7    8
9    10
--  --
11   12

etc.

Pair 1-3 represent aisle #1, pair 2-4 represent aisle #2, pair 5-7 represent aisle #3 and so on. There is no aisle between 3 and 5 because it's the same shelf.

I wonder if there is an elegant formula to get aisle number for a given shelf? Say it must return 1 for 1 or 3, return 2 for 2 or 4, 5 for 9-11 etc.

1

There are 1 best solutions below

9
On BEST ANSWER

Ok writing some scripts, drawing big images, and running to my local library counting shelves there hopefully solved this question. Given the Shelf number $s$ you get the aisle by:

$$ a = 2\left\lfloor \frac{s-1}{4} \right\rfloor + ({(s-1)}\mod 2) +1 $$