• 0
Sign in to follow this  
Followers 0

Sort a table

Question

Posted · Report post

It's not easy to sort a NxM table by human. So, we can sort each one column or raw.

The question is: how to sort a table if you only can sort a row or a column?

For example,

3,3,2,5

4,1,8,6

=>

1,2,3,3

4,5,6,8

0

Share this post


Link to post
Share on other sites

6 answers to this question

  • 0

Posted · Report post

Use the ravel operator, then the sort operator, then the shape operator.

Ravel linearizes a higher-order array.

A linear array can be sorted.

The sorted linear array can then be reshaped to that of the original array.

At IBM, back in the 1960's, Ken Iverson invented APL "read A Programming

Language" that provided operators like ravel and reshape. Google it for more information.

IBM still sells a version of APL that runs on a PC.

0

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Use the ravel operator, then the sort operator, then the shape operator.

There's no "ravel" or "shape" operator in this puzzle. It only has "sort" operator to sort a column or a row.

0

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

There's no "ravel" or "shape" operator in this puzzle. It only has "sort" operator to sort a column or a row.
By sorting rows then columns [or v.v.] you get the smallest number to the upper left and the largest number to the bottom right, and all rows and columns sorted. Repeated sorts of rows and columns have no effect. Elements of the array are not sorted except within a row or a column.

e.g. sort rows: then sort cols:

6 9 4 3 ....... 3 4 6 9 ....... 1 2 4 7

8 2 1 5 ....... 1 2 5 8 ....... 1 3 5 8

7 6 5 4 ....... 4 5 6 7 ....... 3 4 6 8

8 1 4 3 ....... 1 3 4 8 ....... 4 5 6 9

Sorting row1, col1, row2, ... col4, the result is sorted rows and cols, but not sorted table:

1 1 4 7

2 3 5 8

3 4 5 8

4 6 6 9

Once you reach a configuration where rows and cols are sorted, repeated sorting makes no change to the table.

If that's all you can do, you're left with an unsorted table.

To sort the table, you have to do something more than / different from sorting rows or cols.

[a] sort diagonals or mess with its shape somehow.

0

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hint:

Sort has two kinds. One is Ascending sort, the other is descending one.

0

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Question -- are you allowed to look at the table, and use row/col sorts to make the table sorted???

If so, you can use sort_up and sort_down to manipulate numbers to their correct positions, much like solving the "15" puzzle.

I'm assuming you're asking for a procedure to sort tables that could be programmed to sort any and all tables without human "guidance".

0

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Bumping this to the top so maybe the author will reply to the last question.

Thanks ...!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.