//http://codegolf.stackexchange.com/a/70115/42682 module census import StdEnv //Start = v 538 [("CA",38000000.0), ("NH",1300000.0)] //Start = v 2 [("A",1.0)] //Start = v 538 [("DC", 1000000.0), ("RH", 1.0)] Start=v 100 [("A",12.0),("B",8.0),("C",3.0),("D",0.0)] v n s=sortBy(\(a,b)(c,d).b>d)([(t,3.0)\\t<-s|fst t=="DC"]++w(n-3*(length s))[(t,1.0)\\t<-s|fst t<>"DC"]) w 0 s=[(p,r+2.0)\\(p,r)<-s] w n s#s=sortBy(\a b.A a>A b)s #(p,r)=hd s =w(n-1)[(p,r+1.0):tl s] A((_,p),r)=p/sqrt(r*r+r) votes n states # dc = filter (((==)"DC")o fst) states = sortBy (\(a,b)(c,d).b>d) ([(t,3.0) \\ t <- dc] ++ votes` (n-3*length states) [(t,1.0)\\t<-removeMembers states dc]) where votes` 0 states = map (\(p,r).(p,r+2.0)) states votes` n states # states = sortBy (\a b.A a > A b) states # (p,r) = hd states = votes` (n-1) [(p,r+1.0):tl states] A ((_,p),r) = p / sqrt(r*r+r)