Modulo arithmetic problem:

I’m struggling with the problem below, which I’ve put in a script
so it can be easily copied to play with.

(* Suppose I have a square array of items like
   the one below:
   a b c
   d e f
   g h i
   and I know the position in a list of one of those items,
   e.g., item 6 of the list {a, b, c, d, e, f, g, h, i} (item f)
   how can I then identify the row and column in the
   square array in which that item is found; in this
   case, row 2, column 3?*)

(* I'd like to use arithmetic to do that rather
   than some type of loop or search routine and
   my attempts to date with mod, div, etc. always
   present at least one anomaly and the real
  case I'm struggling with is much larger
  that 3 x 3, so I'm looking for something
  general based on the square root of the
  array size. *)

Hi Adam.

set |sqrt| to 3
set i to 6

set row to (i + |sqrt| - 1) div |sqrt|
set column to (i - 1) mod |sqrt| + 1
{row, column}

Thank you Nigel – that’s been torturing me because I’m not nearly so facile with modular arithmetic as you are.