# Square Matrix Permutation

I have a set of items of size N. The items are sorted by probability. A square matrix m[N][N] of those items, in C style memory organization, would have elements with similar probabilities spread out. For example m will be very far from m and all others with similar probability. I need to permutate the elements in a simple way so the more likely ones tend to be closer to 0. It doesn't need to be a square matrix, it can be a vector [N*N]. And it doesn't need to be perfect, just good enough that elements with similar probability are somewhat grouped together. I'm looking for a function f(i,j) to give the position on the permutated matrix/vector. If possible with very simple operations (e.g. no squares and division but programatic conditionals are OK) For a more graphical reference, I'm looking for something like this. [From BBC's The Story of Maths on Cantor's argument] ![alt text] But it doesn't need to be exactly that permutation. Just that the elements walked on the diagonals are mostly grouped nearby. Well, I know this is probably something very simple but it's been many years since school/uni and Wolframalpha isn't helping. Thanks! : http://i.stack.imgur.com/4SXFQ.png
Are you looking for space filling curves? en.wikipedia.org/wiki/Space-filling_curve

### 觉得文章有用就打赏一下文章作者

#### 支付宝扫一扫打赏 #### 微信扫一扫打赏 