| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Majority.Rank
Contents
Synopsis
- type JS = Integer
- type GS = Integer
- type Rank = Integer
- newtype Median = Median (G, G)
- median :: G -> G -> Median
- rankOfMajorityValue :: GS -> MajorityValue (Ranked grade) -> Rank
- majorityValueOfRank :: JS -> GS -> Rank -> MajorityValue (Ranked ())
- positionOfMajorityValue :: GS -> MajorityValue (Ranked grade) -> Rational
- countMerits :: JS -> GS -> Integer
- lastRank :: JS -> GS -> Rank
- countMedian :: JS -> GS -> Median -> Integer
- countMediansBefore :: JS -> GS -> G -> Median -> Integer
- listMediansBefore :: JS -> GS -> G -> Median -> [Median]
- probaMedian :: JS -> GS -> [Rational]
- nCk :: Integral i => i -> i -> i
Convenient type aliases
Rank of a MajorityValue.
Type Median
Ranking and unranking MajorityValues
rankOfMajorityValue :: GS -> MajorityValue (Ranked grade) -> Rank Source #
( returns
the number of possible rankOfMajorityValue gs mv)MajorityValues lower than given mv.
rankOfMajorityValuegs .majorityValueOfRankjs gs<$>[0..lastRankjs gs] == [0..lastRankjs gs]
majorityValueOfRank :: JS -> GS -> Rank -> MajorityValue (Ranked ()) Source #
The inverse of rankOfMajorityValue.
majorityValueOfRankjs gs .rankOfMajorityValuegs ==id
positionOfMajorityValue :: GS -> MajorityValue (Ranked grade) -> Rational Source #
Counting Merits
countMerits :: JS -> GS -> Integer Source #
(
returns the number of possible countMerits js gs)Merits of size js using grades gs.
That is the number of ways to divide a segment of length js
into at most gs segments whose size is between '0' and js.
The formula is: (js+gs-1)·(js+gs-2)·…·(js+1)·js / (gs-1)·(gs-2)·…·2·1
which is: (js+gs-1)nCk(gs-1)
lastRank :: JS -> GS -> Rank Source #
( returns the rank of the lastRank js gs)MajorityValue
composed of js times the highest grade of gs.
.lastRank js gs == countMerits js gs - 1
Counting Medians
countMedian :: JS -> GS -> Median -> Integer Source #
(
returns the number of possible countMedian js gs (Median (l,h)))Merits of length js using grades gs,
which have (l,h) as lower and upper median grades.
This is done by multiplying together
the countMerits to the left of l
and the countMerits to the right of h.
countMediansBefore :: JS -> GS -> G -> Median -> Integer Source #
(
returns the number of possible countMediansBefore js gs previousHigh (Median (low,high)))Merits with js judges and gs grades,
whose is such that Median (l,h)((l,h) < (low, high))
and (previousHigh <= h).
listMediansBefore :: JS -> GS -> G -> Median -> [Median] Source #
(
returns the listMediansBefore js gs previousHigh (Median (low,high)))Medians of possible Merits with js judges and gs grades
with a Median strictly lower than (low,high).
probaMedian :: JS -> GS -> [Rational] Source #
( compute the probability
of each grade to be a probaMedian js gs)MajorityGrade given js judges and gs grades.