From 7518dc643e85cd46f514e02611ec273c8d0bcfdf Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 25 Jan 2016 11:15:59 +0100 Subject: census --- census.icl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 census.icl (limited to 'census.icl') diff --git a/census.icl b/census.icl new file mode 100644 index 0000000..a236fe2 --- /dev/null +++ b/census.icl @@ -0,0 +1,34 @@ +//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=votes 100 [("A",12.0),("B",8.0),("C",3.0),("D",0.0)] + +f=fst +d=snd +q=sqrt +l=length +v n s#d=filter(((==)"DC")o f)s +=sortBy(\(a,b)(c,d).b>d)([(t,3.0)\\t<-d]++w(n-3*(l s))[(t,1.0)\\t<-removeMembers s d]) +w 0 s=map(\(p,r).(p,r+2.0))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/q(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) + -- cgit v1.2.3