So i have to solve a program in C, which is already a challenge, but it's likely finished. The only thing that i do wrong is the algorithm. I have cities and one city will be destroyed while all the neighbor cities get the population from the destroyed city.
The task says a neighbor city that is twice as big as the destroyed city, should get twice as many refugees.
As an example:
Population: 149355 of the destroyed City A
Population: 189069 of the first neighbor City B.
Now, City B should change from 189069 to 205057 citizens. So if i calculated that correct, City B receives 15988 citizens from City A. Why?
What is the mathematical algorithm here? I tried to divide City B trough City A and get around 1.26 for that. However, no matter what i try, i don't know what i need to do in a mathematical way to get to the 205057 population size of the first neighbor city.
Any ideas?
Edit:
All Neighbor cities in this example:
CityB 189069 135
CityC 119250 138
CityD 1365052 144
CityE 92807 162
the number in the middle is the population, the right outer column the distance to the destroyed city.
CityC should change to 129334 in this example, after CityB got its new population.
You just need to compare the populations of all the neighboring cities, the logic is: the larger city will receive the largest fraction of refugees, the second largest will receive the second largest fraction ...
In python this looks like
You should get