How to resolve the algorithm Ranking methods step by step in the Elixir programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ranking methods step by step in the Elixir programming language
Table of Contents
Problem Statement
The numerical rank of competitors in a competition shows if one is better than, equal to, or worse than another based on their results in a competition. The numerical rank of a competitor can be assigned in several different ways.
The following scores are accrued for all competitors of a competition (in best-first order): For each of the following ranking methods, create a function/method/procedure/subroutine... that applies the ranking method to an ordered list of scores with scorers:
See the wikipedia article for a fuller description. Show here, on this page, the ranking of the test scores under each of the numbered ranking methods.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ranking methods step by step in the Elixir programming language
Source code in the elixir programming language
defmodule Ranking do
def methods(data) do
IO.puts "stand.\tmod.\tdense\tord.\tfract."
Enum.group_by(data, fn {score,_name} -> score end)
|> Enum.map(fn {score,pairs} ->
names = Enum.map(pairs, fn {_,name} -> name end) |> Enum.reverse
{score, names}
end)
|> Enum.sort_by(fn {score,_} -> -score end)
|> Enum.with_index
|> Enum.reduce({1,0,0}, fn {{score, names}, i}, {s_rnk, m_rnk, o_rnk} ->
d_rnk = i + 1
m_rnk = m_rnk + length(names)
f_rnk = ((s_rnk + m_rnk) / 2) |> to_string |> String.replace(".0","")
o_rnk = Enum.reduce(names, o_rnk, fn name,acc ->
IO.puts "#{s_rnk}\t#{m_rnk}\t#{d_rnk}\t#{acc+1}\t#{f_rnk}\t#{score} #{name}"
acc + 1
end)
{s_rnk+length(names), m_rnk, o_rnk}
end)
end
end
~w"44 Solomon
42 Jason
42 Errol
41 Garry
41 Bernard
41 Barry
39 Stephen"
|> Enum.chunk(2)
|> Enum.map(fn [score,name] -> {String.to_integer(score),name} end)
|> Ranking.methods
You may also check:How to resolve the algorithm Colour bars/Display step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Loops/While step by step in the Julia programming language
You may also check:How to resolve the algorithm Rosetta Code/Fix code tags step by step in the Nim programming language
You may also check:How to resolve the algorithm Quine step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Find the intersection of a line with a plane step by step in the Evaldraw programming language