Message Boards Message Boards

1
|
4957 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

there is a shorter way to do this?

Posted 10 years ago

Below expose to you my problem I'm trying to solve, I have this list where I want to sort by area, as show below, but do not put attention in the first element of each tuple. Show my code for you to tell me if there is any way to make this shorter, this is because I will occupy larger lists, any idea is welcome, greetings to all.

In[37]:= inter

Out[37]= {{3, 60, 50}, {3, 40, 50}, {3, 30, 30}, {1, 62, 61}}

In[38]:= area = inter[[;; , 2]]*inter[[;; , 3]]

Out[38]= {3000, 2000, 900, 3782}

In[39]:= Do[AppendTo[inter[[i]], area[[i]]], {i, 1, Length[area]}]

In[40]:= inter

Out[40]= {{3, 60, 50, 3000}, {3, 40, 50, 2000}, {3, 30, 30, 900}, {1, 
  62, 61, 3782}}

In[41]:= inter = Sort[inter, #1[[4]] > #2[[4]] &]

Out[41]= {{1, 62, 61, 3782}, {3, 60, 50, 3000}, {3, 40, 50, 2000}, {3,
   30, 30, 900}}

In[42]:= inter = inter[[;; , ;; 3]]

Out[42]= {{1, 62, 61}, {3, 60, 50}, {3, 40, 50}, {3, 30, 30}}
POSTED BY: Luis Ledesma
2 Replies
Posted 10 years ago

Thanks Sandu Ursu,that's what I need, I'm still trying, apparently still working properly

POSTED BY: Luis Ledesma
Posted 10 years ago

I'm not sure, but this might do the work:

SortBy[inter, #[[2]]*#[[3]] &] // Reverse
POSTED BY: Sandu Ursu
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract