Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2012-03-07 14:56:33

rickg
Member
Registered: 2012-03-07
Posts: 1

Need formula for determining Column and Row

Given a matrix where there is some varying number of columns and rows I need to calculate for any given 'tile' its ROW and COLUMN.
Example, a matrix that has 3 columns and 3 rows will have a total of 9 tiles and tile#4 will be in the 1st column, 2nd row, whereas if it were a 4X4 matrix tile#4 would be in the 4th column, first row.

So the knowns at any given time are tileNumber, numberOfRows, and numberOfColumns. From those variables I want a calculation for the associated column and row for any given TileNumber.

FYI The matrixes will all have equal col/row (3X3, 4X4, 5X5)

The needed formulas:
Column = SomeFormula(tileNumber,NumberofRows)
Row = SomeFormula(tileNumber,NumberofColumns)
*keep in mind numberOfRows and numberOfColumns will always be equal in this particular exercise.

Example 3X3 matrix with associated tileNumbers.  So tileNumber 4 in this example has a row value of 2 and a column value of 1.
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9

Offline

#2 2012-03-07 21:20:15

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,049

Re: Need formula for determining Column and Row

Hi rickg

The formulas are:

Column= TileNumber mod NumberofColumns

Row= TileNumber div NumberofColumns + 1

If you have any either questions, you're free to ask.

And welcome to the forum!

Last edited by anonimnystefy (2012-03-07 21:30:35)


“Here lies the reader who will never open this book. He is forever dead.
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#3 2012-03-07 21:24:06

hammana
Member
Registered: 2012-03-02
Posts: 48

Re: Need formula for determining Column and Row

I would rather say that
Row= TileNumber div NumberofColumns + 1

Offline

#4 2012-03-07 21:29:33

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,049

Re: Need formula for determining Column and Row

Yes you're right, forgot to add that.


“Here lies the reader who will never open this book. He is forever dead.
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

Board footer

Powered by FluxBB