summaryrefslogtreecommitdiff
path: root/census.icl
blob: 4b3cade2b5a116f99a1303f7d06e55d298406f65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//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 0s=[(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)