Problem 61061. Government of the Neds, by the Neds, for the Neds - Distribute the Nedsburg City Councilors

The city of Nedsburg consists of several islands, the number of which changes regularly, due to tectonic forces, shoddy civil engineering, and the whims of the city's capricious dictator, Lord Ned.
Recently, a coalition of concerned citizens used a detailed schematic of a device known as a "guillotine" to persuade Lord Ned to try out some radical new ideas like "democracy" and "voting". Lord Ned's survey of voting systems from around the world has convinced him that voting systems are supposed to be unnecessarily Byzantine, resulting in him coming up with this method for distributing the Nedsburg city councilors:
  • Start with a baseline of N = 20 councilors, but increase this baseline to N = 2n if the number of islands, n, exceeds 10.
  • The island with the highest proportion of people named Ned is the super special island. They get only one councilor, but that councilor gets lots of fancy titles and special powers and a big floppy hat.
  • The rest of the islands get the remaining N-1 councilors, distributed proportionally according to their share of the remaining population that isn't named Ned. (The population of the super special island is ignored for this calculation; they already have their one special councilor. With a floppy hat.)
  • Lord Ned was intrigued by the "guillotine" idea, but was ultimately convinced that fractional councilors would be more trouble than they were worth, and so the number of councilors for each island is rounded to the nearest whole number.
  • However, each island must have at least one councilor.
  • These last two adjustments mean that the total number of councilors may differ from the original baseline.
Given two n-element column vectors, pop and neds, containing the population and number of Neds in that population, respectively, for each island, return an n-element column vector, c, of the number of councilors each island gets to vote for, and scalar special that contains the index of the island that has the super special councilor.
Examples
pop = [10;7;9];
neds = [5;3;7];
Island 3 has the highest proportion of Neds (7/9), so gets the one special councilor. Island 1 has 5 people not named Ned. Island 2 has 4. Therefore island 1 gets 5/9 of the remaining 19 councilors and island 2 gets 4/9.
>> 5*19/9
ans =
10.5556
>> 4*19/9
ans =
8.4444
Rounding these results in a final tally of 11, 8, and 1 councilors.
[c,idx] = neddymander(pop,neds)
c =
11
8
1
idx =
3
To illustrate the rounding rules:
pop = [100;100;100];
neds = [1;99;98];
Now island 2 has the highest proportion of Neds (99/100). Island 1 has 99 non-Neds, and island 3 has 2. Therefore island 1 gets 99/101 of the remaining 19 councilors, and island 3 gets 2/101.
>> 19*99/101
ans =
18.6238
>> 19*2/101
ans =
0.3762
Rounding these results in 19 councilors for island 1 and 0 for island 2. Island 2 therefore gets the minimum one councilor.
[c,idx] = neddymander(pop,neds)
c =
19
1
1
idx =
2
The minimum and rounding rules result in 21 councilors, in this case.
Assumptions
The population of Neds cannot exceed the total population. Uninhabited islands don't get to vote. You can therefore assume that pop(k) > 0 and 0 ≤ neds(k)pop(k), for all k. If there is only one island, then there is no need to distribute the councilors, so you can assume n ≥ 2.

Solution Stats

52.33% Correct | 47.67% Incorrect
Last Solution submitted on Nov 26, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers113

Suggested Problems

More from this Author33

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!