Ranking methods: Difference between revisions

Add APL
(Add Cowgol)
(Add APL)
Line 298:
5 41 Barry
7 39 Stephen</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
 
These functions each take a 2-by-N matrix, where the first column contains
the score, and the second column contains the name. They return a 3-by-N
matrix, with the ranking added.
 
<lang apl>standard ← ∊∘(⌊\¨⊢⊂⍳∘≢)∘(1,2≠/⊢)∘(1⌷[2]⊢),⊢
modified ← ∊∘(⌈\∘⌽¨⊢⊂⍳∘≢)∘(1,2≠/⊢)∘(1⌷[2]⊢),⊢
dense ← (+\1,2≠/1⌷[2]⊢),⊢
ordinal ← ⍳∘≢,⊢
fractional ← ∊∘((≢(/∘⊢)+/÷≢)¨⊢⊂⍳∘≢)∘(1,2≠/⊢)∘(1⌷[2]⊢),⊢</lang>
 
{{out}}
 
<pre> ⍝ Input scores table from task:
scores←⍉⍪44,⊂'Solomon'
scores⍪←42,⊂'Jason'
scores⍪←42,⊂'Errol'
scores⍪←41,⊂'Garry'
scores⍪←41,⊂'Bernard'
scores⍪←41,⊂'Barry'
scores⍪←39,⊂'Stephen'
⍝ Apply each function to it
standard scores
1 44 Solomon
2 42 Jason
2 42 Errol
4 41 Garry
4 41 Bernard
4 41 Barry
7 39 Stephen
modified scores
1 44 Solomon
3 42 Jason
3 42 Errol
6 41 Garry
6 41 Bernard
6 41 Barry
7 39 Stephen
dense scores
1 44 Solomon
2 42 Jason
2 42 Errol
3 41 Garry
3 41 Bernard
3 41 Barry
4 39 Stephen
ordinal scores
1 44 Solomon
2 42 Jason
3 42 Errol
4 41 Garry
5 41 Bernard
6 41 Barry
7 39 Stephen
fractional scores
1 44 Solomon
2.5 42 Jason
2.5 42 Errol
5 41 Garry
5 41 Bernard
5 41 Barry
7 39 Stephen </pre>
 
=={{header|AWK}}==
2,114

edits