Created
June 22, 2017 15:03
-
-
Save anonymous/c147082931d7dbebabab862ec33757d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- L'exercice est de passer le fichier qui se trouve ici | |
-- https://vote.gnome.org/blt.php?election_id=25 | |
-- et d'en extraire les informations | |
import Data.List | |
woBoundaries = | |
let r = reverse . drop 1 | |
in r . r | |
clusters_of size list = | |
map (take size) $ map (`drop` list) [0..length list - size] | |
compare_lists xs ys | |
| length xs > length ys = GT | |
| otherwise = LT | |
-- compare_size_then_occurences @xs(sx,ox) @xs(sy,ox) = | |
-- LT | |
clusters_in range list = | |
concat | |
$ concat | |
$ map (\x -> map (clusters_of x) list) range | |
love x = | |
sortBy compare_lists | |
. map ( \x -> (length x, x !! 0) ) | |
. filter ((> 1) . length) | |
. group | |
. filter ((> 1) . length) | |
. sort | |
. concat | |
. map (clusters_of x) | |
go = do | |
content <- getContents | |
let entries = drop 1 $ lines content | |
let votes = | |
map (woBoundaries . words) | |
$ takeWhile (/= "0") entries | |
let candidates = | |
map woBoundaries | |
$ drop 1 | |
$ dropWhile (/= "0") entries | |
mapM print $ love 4 votes ++ love 5 votes | |
-- $ clusters_in [4..5] votes | |
main = go |
bartavelle
commented
Jun 22, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment