Problem 1888. Get ranking of a combination
I have the numbers pulled without replacement from the set [1 2 3 4 5 6 7 8 9 10 11 12 13]; They are then ordered from least to greatest.
So a selection of [3 2 9], [9 2 3] are both considered to be [2 3 9].
There are 286 unique selections possible. These can be ordered in lexicographic order:
Element 1 = [ 1 2 3]
Element 2 = [ 1 2 4]
Element 3 = [ 1 2 5]
Element 4 = [ 1 2 6]
Element 5 = [ 1 2 7]
Element 6 = [ 1 2 8]
Element 7 = [ 1 2 9]
Element 8 = [ 1 2 10]
Element 9 = [ 1 2 11]
Element 10 = [ 1 2 12]
Element 11 = [ 1 2 13]
Element 12 = [ 1 3 4]
Element 13 = [ 1 3 5]
Element 14 = [ 1 3 6]
Element 15 = [ 1 3 7]
...
Element 285 = [10 12 13]
Element 286 = [11 12 13]
Given the three ordered values as a row vector, return the element number.
Do this with an eye for speed, though it is not tested for here.
Looking for a way to do this WITHOUT generating the nchoosek matrix.
Solution Stats
Problem Comments
-
1 Comment
Dyuman Joshi
on 30 Oct 2022
Test suite has been updated with new cases.
Solution Comments
Show commentsProblem Recent Solvers49
Suggested Problems
-
1196 Solvers
-
Find common elements in matrix rows
2632 Solvers
-
Find the largest value in the 3D matrix
1521 Solvers
-
66 Solvers
-
There are 10 types of people in the world
1120 Solvers
More from this Author51
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!