I want to sort a list based on rarity, so a list like {1,3,1,5,5} should return {5,5,1,1,3}. I also want the highest number first if the quantity is the same. For instance if theres 2x 1 and 2x 5 like above, 5 should go first. Im using a ti 84 plus cet.

Can someone help?

1: Please don't double-post on threads, per the Rules. We like forum threads here to be clean. Sometimes it takes awhile for someone to come along who can help you. Just be patient!

2: I've never tried this, but I imagine you could sort the list in descending order, test if a number appears twice (or more), and if not, then store that number to a separate list, and then add those numbers back to the end of the original list. There's probably a better way to do it, and I'm not completely sure the method I described would work, but it's something.

It's not exactly what you're looking for, but it should help you get there.

Timothy Foster - @tfAuroratide

Auroratide.com - Go here if you're nerdy like me

I think the SortD( command is on CE-T's. That should do what you want, if I understand correctly.

That's not quite what he's looking for. It would seem he would like the list to be sorted first by frequency, *then* by descending value, if there is a tie. Basically starting with the routine provided by Timothy, then sorting the entries with identical frequencies via SortD(. I don't have time to throw the code together right now but it shouldn't be too long.

The solution to a complex problem is often a simple answer.

EDIT:

This is what I was able to come up with. It sorts the list in descending order, then counts how many times each number appears using the routine Timothy Foster linked. However, I used SortD( rather than SortA( so that the numbers appear in descending order. This is important for when we find the max in the list, as if there are more than one number with the same frequency, the first occurrence will be used. Since we want the higher values first, in our output, they need to be first in the input. This code then looks for the maximum value in the frequency of the numbers, and the corresponding value. It then appends the value to L1 at the frequency it occurs. It then removes that value from L2 and L3, so there isn't an infinite loop. It repeats this until there are no more values in L2. The sorted values will be in L1. In addition, since L2 and L3 will be empty, and the only other variables used are reals, you shouldn't have to do any cleanup.

```
DelVar L₂DelVar L₃SortD(L₁
SetUpEditor
For(θ,1,dim(L₁
L₁(θ→L₂(1+dim(L₂
sum(L₁=Ans→L₃(dim(L₂
θ-1+Ans→θ
End
DelVar L₁
SetUpEditor
While dim(L₂
1+sum(not(cumSum(L₃=max(L₃→θ
L₃(θ)→N
For(E,1,N
L₂(θ→L₁(1+dim(L₁
End
For(E,θ+1,dim(L₂
L₂(E→L₂(E-1
L₃(E→L₃(E-1
End
dim(L₂)-1→dim(L₂
dim(L₃)-1→dim(L₃
End
```