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

Post History

71%
+3 −0
Sandbox Find good coalitions [FINALIZED]

posted 3y ago by celtschk‭  ·  edited 1y ago by trichoplax‭

#8: Post edited by user avatar trichoplax‭ · 2023-06-19T10:25:07Z (over 1 year ago)
Add finalized tag now that the sandbox can be filtered to exclude tags
Find good coalitions [FINALIZED]
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 <a class="badge is-tag">code-golf</a>, the shortest code wins.

Test cases:

```text
{"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]]
```
#7: Post edited by user avatar celtschk‭ · 2021-10-04T13:38:02Z (about 3 years ago)
  • Find good coalitions
  • Find good coalitions [FINALIZED]
#6: Post edited by user avatar celtschk‭ · 2021-10-01T17:12:52Z (about 3 years ago)
Added a note that the order in the output does not matter
  • 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, …).
  • This is <a class="badge is-tag">code-golf</a>, the shortest code wins.
  • Test cases:
  • ```text
  • {"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]]
  • ```
  • 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 <a class="badge is-tag">code-golf</a>, the shortest code wins.
  • Test cases:
  • ```text
  • {"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]]
  • ```
#5: Post edited by user avatar celtschk‭ · 2021-09-30T06:27:32Z (about 3 years ago)
  • 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, …).
  • This is <a class="badge is-tag">code-golf</a>, the shortest code wins.
  • Test cases:
  • ```text
  • {"nano": 25}
  • → [["nano"]]
  • {"vi": 20, "Emacs": 21}
  • → [["Emacs"]]
  • {"vi": 20, "Emacs": 20}
  • → [["vi": 20, "Emacs": 20]]
  • {"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]]
  • ```
  • 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, …).
  • This is <a class="badge is-tag">code-golf</a>, the shortest code wins.
  • Test cases:
  • ```text
  • {"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]]
  • ```
#4: Post edited by user avatar celtschk‭ · 2021-09-30T06:26:24Z (about 3 years ago)
Fixed test case thanks to @Moshi
  • 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, …).
  • This is <a class="badge is-tag">code-golf</a>, the shortest code wins.
  • Test cases:
  • ```text
  • {"nano": 25}
  • → [["nano"]]
  • {"vi": 20, "Emacs": 21}
  • → [["Emacs"]]
  • {"vi": 20, "Emacs": 20}
  • → []
  • {"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]]
  • ```
  • 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, …).
  • This is <a class="badge is-tag">code-golf</a>, the shortest code wins.
  • Test cases:
  • ```text
  • {"nano": 25}
  • → [["nano"]]
  • {"vi": 20, "Emacs": 21}
  • → [["Emacs"]]
  • {"vi": 20, "Emacs": 20}
  • → [["vi": 20, "Emacs": 20]]
  • {"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]]
  • ```
#3: Post edited by user avatar General Sebast1an‭ · 2021-09-30T05:54:45Z (about 3 years ago)
Find good coalitions
  • 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, …).
  • This is code golf, the shortest code wins.
  • Test cases:
  • ```text
  • {"nano": 25}
  • → [["nano"]]
  • {"vi": 20, "Emacs": 21}
  • → [["Emacs"]]
  • {"vi": 20, "Emacs": 20}
  • → []
  • {"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]]
  • ```
  • 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, …).
  • This is <a class="badge is-tag">code-golf</a>, the shortest code wins.
  • Test cases:
  • ```text
  • {"nano": 25}
  • → [["nano"]]
  • {"vi": 20, "Emacs": 21}
  • → [["Emacs"]]
  • {"vi": 20, "Emacs": 20}
  • → []
  • {"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]]
  • ```
#2: Post edited by user avatar celtschk‭ · 2021-09-29T16:45:43Z (about 3 years ago)
  • Find possible coalitions
  • Find good coalitions
#1: Initial revision by user avatar celtschk‭ · 2021-09-29T16:45:23Z (about 3 years ago)
Find possible coalitions
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, …).

This is code golf, the shortest code wins.

Test cases:

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

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

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

{"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]]
```