From 685602ca6a4af17e6e6620527d8c0e6897393b2c Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Wed, 1 Feb 2017 11:31:58 +1100 Subject: Fixed candidate ordering bug for groups AA and beyond --- src/Candidate.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Candidate.hs b/src/Candidate.hs index 21f9736..e92fd05 100644 --- a/src/Candidate.hs +++ b/src/Candidate.hs @@ -59,7 +59,7 @@ readCandidates inputFile state = do if (Either.isRight t1) && (Maybe.isJust t2) then readFunc (t3:r) tx else readFunc r tx - raw <- readFunc [] e >>= return . (List.sort) + raw <- readFunc [] e >>= return . (List.sortBy candRecComp) IO.hClose h return (makeAboveBallot raw, makeBelowBallot raw) @@ -67,6 +67,18 @@ readCandidates inputFile state = do +-- assumes there are at least two items in each list +-- see the above function for the things it gets applied on for why +candRecComp :: [String] -> [String] -> Ordering +candRecComp a b = + let lenResult = compare (length (head a)) (length (head b)) + in if (lenResult == EQ) + then compare (take 2 a) (take 2 b) + else lenResult + + + + -- very hacky, pls revise makeAboveBallot :: [[String]] -> AboveLineBallot makeAboveBallot input = -- cgit