Determining Winning Combinations of Parties with >50% Votes

Click For Summary
SUMMARY

This discussion focuses on determining winning combinations of political parties that collectively achieve over 50% of the votes, using a Groovy script. The parties and their respective vote percentages are provided, with the script employing a brute force method to calculate all possible combinations. The script identifies 502 winning combinations ranging from 51% to 100%. Participants express appreciation for the simplicity of the solution despite initial confusion regarding coding.

PREREQUISITES
  • Understanding of Groovy programming language
  • Basic knowledge of combinatorial mathematics
  • Familiarity with data structures such as lists and maps
  • Concept of coalition governments and voting systems
NEXT STEPS
  • Learn Groovy programming fundamentals
  • Explore combinatorial algorithms for generating subsets
  • Study coalition formation in political science
  • Investigate optimization techniques for large datasets
USEFUL FOR

Political analysts, data scientists, software developers, and anyone interested in electoral systems and coalition dynamics.

Ryan_m_b
Staff Emeritus
Science Advisor
Homework Helper
Insights Author
Messages
5,964
Reaction score
727
This is born out of musings around coalition governments that arise from the party with the most votes not achieving ≥50% of the votes (as opposed to emergency coalitions).

Taking the figures below how would one go about determining all the possible combinations of parties who combined have >50% of the votes without sitting down and working them out one by one?

Kid gloves please :redface: I haven't studied maths for the better part of a decade...

Parties / Percentage of votes

Pink / 21
Orange / 19
Brown / 16
Blue / 10
Green / 10
Tan / 8
Red / 5
Black / 4
Purple / 4
White / 3
 
Physics news on Phys.org


Brute force my friend !
Here is a groovy script that answers your question:
Code:
def X=[Pink:21, Orange:19, Brown:16, Blue:10, Green:10, Tan:8, Red:5, Black:4, Purple:4, White:3]
def XS=X.keySet() as List
def N=XS.size()
def F; F={ ix,n ->
	def L0=[XS[ix]]
	if(n==1) return [L0]
	def L=[]
	for(def j=ix; j<N-1; j++) { 
		F(j+1, n-1).each{ L<<(L0+it) }
	}
	L
}
def OK=[:]
for(def i=0;i<N;i++) {
	for(def j=1;j<=N-i;j++) {
		def c=F(i,j)
		c.each{ 
			def s=0; it.each { s+=X[it]} 
			if(s>50) OK[it]=s 
		}
	}
}
OK.keySet().sort{x,y->OK[y]<=>OK[x]}.each{ println "$it: ${OK[it]}%" }
I don't post the result since there are 502 winning combinations going all the way from 51% up to 100% :smile:
 


oli4 said:
Brute force my friend !
Here is a groovy script that answers your question:
I don't post the result since there are 502 winning combinations going all the way from 51% up to 100% :smile:
Wow thanks a lot! To be honest I'm not really sure how to work code lol but it's good to know that there's a relatively simple way to get it done. Thanks!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 93 ·
4
Replies
93
Views
10K
  • · Replies 65 ·
3
Replies
65
Views
12K