fork(1) download
  1. function z = f(r, c)
  2. z = hilb(max([r c]));
  3. z = z(1:r, 1:c);
  4. n = 1:r * c;
  5. for i = 1:r + c - 1
  6. m = z == 1 / i;
  7. w = sum(m(:));
  8. z(m) = flip(n(1:w), 2 + mod(i, 2));
  9. n(1:w) = [];
  10. end
  11. end
  12. f(3, 3), f(4, 2), f(3, 5), f(1, 8)
Success #stdin #stdout 0.26s 411840KB
stdin
Standard input is empty
stdout
ans =

   1   2   6
   3   5   7
   4   8   9

ans =

   1   2
   3   5
   4   6
   7   8

ans =

    1    2    6    7   12
    3    5    8   11   13
    4    9   10   14   15

ans =

   1   2   3   4   5   6   7   8