Jump to content


Welcome to BrainDen.com - Brain Teasers Forum

Welcome to BrainDen.com - Brain Teasers Forum. Like most online communities you must register to post in our community, but don't worry this is a simple free process. To be a part of BrainDen Forums you may create a new account or sign in if you already have an account.
As a member you could start new topics, reply to others, subscribe to topics/forums to get automatic updates, get your own profile and make new friends.

Of course, you can also enjoy our collection of amazing optical illusions and cool math games.

If you like our site, you may support us by simply clicking Google "+1" or Facebook "Like" buttons at the top.
If you have a website, we would appreciate a little link to BrainDen.

Thanks and enjoy the Den :-)
Guest Message by DevFuse
 

Photo
- - - - -

Sort a table


  • Please log in to reply
6 replies to this topic

#1 Benson

Benson

    Junior Member

  • Members
  • PipPip
  • 23 posts

Posted 28 September 2007 - 05:08 AM

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

#2 bonanova

bonanova

    bonanova

  • Moderator
  • PipPipPipPip
  • 5841 posts
  • Gender:Male
  • Location:New York

Posted 28 September 2007 - 06:16 AM

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
The greatest challenge to any thinker is stating the problem in a way that will allow a solution.
- Bertrand Russell

#3 Benson

Benson

    Junior Member

  • Members
  • PipPip
  • 23 posts

Posted 28 September 2007 - 07:59 AM

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

#4 bonanova

bonanova

    bonanova

  • Moderator
  • PipPipPipPip
  • 5841 posts
  • Gender:Male
  • Location:New York

Posted 03 October 2007 - 04:40 AM

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 [b] mess with its shape somehow.
  • 0
The greatest challenge to any thinker is stating the problem in a way that will allow a solution.
- Bertrand Russell

#5 Benson

Benson

    Junior Member

  • Members
  • PipPip
  • 23 posts

Posted 03 October 2007 - 04:45 PM

Hint:
Sort has two kinds. One is Ascending sort, the other is descending one.
  • 0

#6 bonanova

bonanova

    bonanova

  • Moderator
  • PipPipPipPip
  • 5841 posts
  • Gender:Male
  • Location:New York

Posted 06 October 2007 - 09:08 AM

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
The greatest challenge to any thinker is stating the problem in a way that will allow a solution.
- Bertrand Russell

#7 bonanova

bonanova

    bonanova

  • Moderator
  • PipPipPipPip
  • 5841 posts
  • Gender:Male
  • Location:New York

Posted 12 October 2007 - 11:01 AM

Bumping this to the top so maybe the author will reply to the last question.
Thanks ...!
  • 0
The greatest challenge to any thinker is stating the problem in a way that will allow a solution.
- Bertrand Russell




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users