srand 1374760505; // just to make the docs reproducible, // remove to use default srand(time()) // players // a0:a4 = { "Rick", "Phil", "Harry", "Sam", "Joe" }; // simulated scores // b0:g4 = { irand(11) }; // find all occurrences of max score // {h0,h1:i1} = find(b0:g4,max(b0:g4)); eval; // range 1...h0 in column c // #define H0(c) Cell(c,1):Cell(c,h0) // column j will hold the unique row indices from column i // copy H0("j") H0("i"); sort H0("j") uniq j0; // n will remain constant while j0 counts down to zero // n = j0; eval symbols; format "%g"; print; // source and destination for copy // #define N 5 // number of players #define C1 "a" // start column for scores #define CM "g" // end column for scores #define RROW n-j0 // row index for find result #define SROW cell("j",RROW) // source row from find result #define DROW N+RROW // destination row #define SRC Cell(C1,SROW):Cell(CM,SROW) #define DEST(c1,cM) Cell(c1,DROW):Cell(cM,DROW) // copy and sort the tied players scores // while( j0-- > 0) { copy DEST(C1,CM) SRC; sort DEST(CM,C1); } print Cell(C1,N+1):Cell(CM,N+n);