Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Find good coalitions [FINALIZED]

+3
−0

As you might know, there were elections in Germany, and now the parties have to form a government coalition. Let's help them with it!

A good coalition has the strict majority of seats (that is, more seats than the opposition). Moreover you don't want more parties than necessary in a coalition, that is, if you still have a majority after removing one of the parties, it's not a good coalition.

You are given a list of parties and their number of seats. Your task is to output a list of good coalitions, where each coalition is given by a list of its members. For this task, a coalition may also consist of a single party.

Input and output may be in any suitable form (e.g. they need not be lists, but can be sets, dictionaries, XML, …). Note that the order of the parties in each coalition does not matter, nor does the order of coalitions. For example, the output [["nano", "vi"], ["nano", Emacs"], ["vi", "Emacs"]] is equivalent to [["vi", Emacs"], ["Emacs", "nano"], ["nano", "vi"]].

This is code-golf, the shortest code wins.

Test cases:

{"nano": 25}
 → [["nano"]]

{"vi": 20, "Emacs": 21}
 → [["Emacs"]]

{"vi": 20, "Emacs": 20}
 → [["vi", "Emacs"]]

{"nano": 20, "vi": 15, "Emacs": 12}
 → [["nano", "vi"], ["nano", Emacs"], ["vi", "Emacs"]]

{"nano": 25, "vi": 14, "Emacs": 8, "gedit": 6}
 → [["nano", "vi"], ["nano", "Emacs"], ["nano", "gedit"], ["vi", "Emacs", "gedit"]]

{"nano": 16, "vi": 14, "Emacs": 8, "gedit": 6}
 → [["nano", "vi"], ["nano", "Emacs"], ["vi", "Emacs", "gedit"]]

{"nano": 10, "vi": 10, "Emacs": 5, "gedit": 5}
 → [["nano", "vi"], ["nano", "Emacs", "gedit"], ["vi", "Emacs", "gedit]]
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

{"vi": 20, "Emacs": 20} → [] (2 comments)