Formula to calculate an order position - MOVED

mathg

New member
Joined
Oct 19, 2015
Messages
1
Hello!

Here is a problem I have at work that I've been trying to solve, but I can't seem to find the solution.

Just to help you understand what's going on, my problem is mathematical but from a web developer standpoint. I'm trying to organize elements in the page according to the window screen. I need to calculate which position they will be in different scenario.

Here is the default grid :

attachment.php


And here is the grid at another breakpoint :

attachment.php


The numbers in second image are to identify which blocks is supposed to be at that position.

Basically, here is what happens

Original positionResult position
11
22
35
43
54
67
76
89
910
108
1111
1212

That patterns repeat itself indefinitely.

What I'm trying to find a some sort of formula that would help me convert any original position to their new position.

Thank you!
 

Attachments

  • ECMLn.jpg
    ECMLn.jpg
    16.8 KB · Views: 14
  • PiAfx.jpg
    PiAfx.jpg
    11.3 KB · Views: 14
I can see what is happening, but why use a function to relate them? You can get their locations separately and explicitly as a function of the page width. Lets say page width is 2 and 3 in your examples

say the top row is row 0, first column is column 0.

Position(k^th small window, pagewidth) = (row,col)

where

row = (pagewidth+1)*floor((k-1)/pagewidth)

col = (k-1 mod pagewidth)

and


Position(k^th long window, pagewidth) = row

where

row = k+floor((k-1)/pagewidth)
 
Top