Jump to content
BrainDen.com - Brain Teasers
  • 0
Sign in to follow this  
Guest

Sort a table

Question

Guest

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

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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.

Share this post


Link to post
Share on other sites
  • 0
Guest
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.

Share this post


Link to post
Share on other sites
  • 0
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.

Share this post


Link to post
Share on other sites
  • 0

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".

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...