Jump to content

Ranking methods: Difference between revisions

J
(Improve description)
(J)
Line 185:
 
C:\Users\RC\Code></pre>
 
=={{header|J}}==
Implementation:
 
<lang J>competitors=:<;._1;._2]0 :0
44 Solomon
42 Jason
42 Errol
41 Garry
41 Bernard
41 Barry
39 Stephen
)
 
scores=: {."1
 
standard=: 1+i.~
modified=: 1+i:~
dense=: #/.~ # #\@~.
ordinal=: #\
fractional=: #/.~ # ] (+/%#)/. #\
 
rank=:1 :'<"0@u@:scores,.]'</lang>
 
Note that we assume that the competitors are already in the right order. Also, of course (as is common when using J) we use the J command line, because that is portable across operating systems (for example: the OS command line is difficult to use on phones).
 
Task examples:
 
<lang J> standard rank competitors
┌─┬──┬───────┐
│1│44│Solomon│
├─┼──┼───────┤
│2│42│Jason │
├─┼──┼───────┤
│2│42│Errol │
├─┼──┼───────┤
│4│41│Garry │
├─┼──┼───────┤
│4│41│Bernard│
├─┼──┼───────┤
│4│41│Barry │
├─┼──┼───────┤
│7│39│Stephen│
└─┴──┴───────┘
modified rank competitors
┌─┬──┬───────┐
│1│44│Solomon│
├─┼──┼───────┤
│3│42│Jason │
├─┼──┼───────┤
│3│42│Errol │
├─┼──┼───────┤
│6│41│Garry │
├─┼──┼───────┤
│6│41│Bernard│
├─┼──┼───────┤
│6│41│Barry │
├─┼──┼───────┤
│7│39│Stephen│
└─┴──┴───────┘
dense rank competitors
┌─┬──┬───────┐
│1│44│Solomon│
├─┼──┼───────┤
│2│42│Jason │
├─┼──┼───────┤
│2│42│Errol │
├─┼──┼───────┤
│3│41│Garry │
├─┼──┼───────┤
│3│41│Bernard│
├─┼──┼───────┤
│3│41│Barry │
├─┼──┼───────┤
│4│39│Stephen│
└─┴──┴───────┘
ordinal rank competitors
┌─┬──┬───────┐
│1│44│Solomon│
├─┼──┼───────┤
│2│42│Jason │
├─┼──┼───────┤
│3│42│Errol │
├─┼──┼───────┤
│4│41│Garry │
├─┼──┼───────┤
│5│41│Bernard│
├─┼──┼───────┤
│6│41│Barry │
├─┼──┼───────┤
│7│39│Stephen│
└─┴──┴───────┘
fractional rank competitors
┌───┬──┬───────┐
│1 │44│Solomon│
├───┼──┼───────┤
│2.5│42│Jason │
├───┼──┼───────┤
│2.5│42│Errol │
├───┼──┼───────┤
│5 │41│Garry │
├───┼──┼───────┤
│5 │41│Bernard│
├───┼──┼───────┤
│5 │41│Barry │
├───┼──┼───────┤
│7 │39│Stephen│
└───┴──┴───────┘</lang>
 
=={{header|Python}}==
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.