I was thinking that as long as the values are mostly zeros (which they typically should be) it wouldn't take too long. ]]>

` ``SortD(L2 sum(L2≠0->dim(L2`

Instead of doing

` ``While not(A>dim(L₂ 1+sum(not(cumSum(L₂=0→A seq(L₂(A+(A≥Ans)),A,1,dim(L₂)-1→L₂ End`

Why not instead do

` ``SortD(L₂ While A≠0 and B≤dim(L₂ L₂(B)→A B+1→B End B-2→dim(L₂`

With A=1 and B=1 being set before the loop

Based on my testing, it seems to function the same but is substantially more efficient due to it only editing the list once, not using sequence, and ending sooner when there are fewer values (The other code takes longer the more values there are).

I am not entirely sure if this works exactly the same but so far it seems like it would.

` ``seq(sum(0>L₁-X),X,1,max(L₁)+1)+1 ΔList(Ans 1+sum(not(cumSum(Ans=max(Ans // Generate a sequence of the counts of the numbers less than X from X=1 to the max of the list+1. // take the deltalist to generate the individual counts of the numbers // find the position of the highest count in Ans. That will be equal to the integer mode`

However, Multi-modal can be difficult. The code below returns a list of 0's and 1's where all the 1's are the indices equivalent to each mode. For example, an output of {0,0,1,0,0,0,1,0} would be multi-modal with a mode of {3,7}. However, I don't have the time right now to write the code to find the indices of all elements greater than 0.

` ``seq(sum(0>L₁-X),X,1,max(L₁)+1)+1 ΔList(Ans 1=(Ans-(max(Ans)-1`

Edit: I found more time

See the following commented and uncommented codes:

` ``seq(sum(0>L₁-X),X,1,max(L₁)+1)+1 ΔList(Ans 1=(Ans-(max(Ans)-1 seq(XAns(X),X,1,dim(Ans→L₂ While not(A>dim(L₂ 1+sum(not(cumSum(L₂=0→A seq(L₂(A+(A≥Ans)),A,1,dim(L₂)-1→L₂ End L₂`

` ``//count the elements less than X from X=1 to the max of the list +1 seq(sum(0>L₁-X),X,1,max(L₁)+1)+1 // generate individual counts of each number ΔList(Ans // subtract the maximum of the list-1 and return a binary list where the index is equal to a mode 1=(Ans-(max(Ans)-1 // convert the list into its indices, only where the value is non-zero seq(XAns(X),X,1,dim(Ans→L₂ //While A is not more than dim L2 While not(A>dim(L₂ //find the index of the first 0 in the list. If there is no 0, return 1+dim(L2 1+sum(not(cumSum(L₂=0→A //remove the 0 seq(L₂(A+(A≥Ans)),A,1,dim(L₂)-1→L₂ //repeat until no 0's exist in the list End //display the modes L₂`

I actually didn't notice that 4th line could be removed.

And I had actually gone on a long search on google for some code and the best I found was about 30 lines long and used 6 lists. I thought it could be much simpler, however I still need to figure out if I can get multiple modes. I will go check out that link you provided to get ideas. Thank you again. ]]>

Here are some mode algorithms designed and optimized by the community (myself included) to compare to. My immediate suggestions would be to drop some parentheses and make some other small changes:

` ``:SortA(L₁ :seq(sum(L₁=X),X,min(L₁),max(L₁)→L₂ :-1+max(seq(X,X,min(L₁),max(L₁))(L₂=max(L₂→dim(L₂ :L₁(1+sum(L₂→C`

Aside from that, further improvements would have to be structural. The biggest lapse in structural efficiency I can see is the use of `SortA(` (which isn't the fastest) and the continuous `seq(` commands. Checking over only the elements of L₁, rather than all possible elements between the min and max would be faster, though I haven't looked at the code thoroughly enough yet to see how to actually implement such a change.

Given the bounds of what the list can be*, It can determine the largest mode of X.

(1 and 100 are the bounds in this example)

SortA(L1

seq(sum((L1=X)),X,1,100)->L2

max(seq(x,x,1,100)(L2=max(L2)))->C

C-1->dim(L2

L1(sum(L2)+1)->C

I was wondering how I could check for multiple modes (and store them) and if my code could be more efficient. Any help is appreciated.

*With an addition of min(L1) and max(L1) in place of the bounds, you can just check for them.

]]>