fork download
  1. M = reshape( 1:64, [ 8 8 ] )
  2. M = M.'; %'// matlab works column major - so we first transform the matrix
  3. M(:, 2:2:end) = M(end:-1:1, 2:2:end); %// filp up-down every second column
  4. snake = M(:).'
Success #stdin #stdout 0.17s 65056KB
stdin
Standard input is empty
stdout
M =

    1    9   17   25   33   41   49   57
    2   10   18   26   34   42   50   58
    3   11   19   27   35   43   51   59
    4   12   20   28   36   44   52   60
    5   13   21   29   37   45   53   61
    6   14   22   30   38   46   54   62
    7   15   23   31   39   47   55   63
    8   16   24   32   40   48   56   64

snake =

 Columns 1 through 16:

    1    9   17   25   33   41   49   57   58   50   42   34   26   18   10    2

 Columns 17 through 32:

    3   11   19   27   35   43   51   59   60   52   44   36   28   20   12    4

 Columns 33 through 48:

    5   13   21   29   37   45   53   61   62   54   46   38   30   22   14    6

 Columns 49 through 64:

    7   15   23   31   39   47   55   63   64   56   48   40   32   24   16    8