Several island economies trade around an inner sea. Island j (numbered from 0) has the parameters in countries[j], a dict with the keys "c0", "c1", "T", "I", "G", "m". All amounts are millions of crowns per year, and for each island:
- consumption: C_j = c_{0,j} + c_{1,j} \, (Y_j - T_j), with a fixed tax T_j;
- planned investment I_j and government purchases G_j are fixed;
- imports: M_j = m_j \, Y_j;
shares[i][j]is the fraction of islandi's imports bought from islandj. Each row ofsharesadds up to 1 andshares[i][i] = 0;- island
j's exports are what the others buy from it: X_j = \sum_i \text{shares}[i][j] \cdot M_i.
Every island is in equilibrium at the same time:
Y_j = C_j + I_j + G_j + X_j - M_j \quad \text{for every } j
Write port_outputs(countries, shares) that returns the list of equilibrium outputs [Y_0, Y_1, \dots].
The tests build each island with the helper isle(c0, c1, T, I, G, m), which returns the dict {"c0": c0, "c1": c1, "T": T, "I": I, "G": G, "m": m}; you may use it too.
Examples
Input: countries = [isle(60, 0.75, 100, 100, 150, 0.25), isle(40, 0.5, 50, 80, 100, 0.25)],
shares = [[0, 1], [1, 0]]
Output: [720.0, 500.0]
Explanation: island 0 imports 0.25 * 720 = 180, all from island 1; island 1 imports 125,
all from island 0. Island 0: C = 60 + 0.75 * 620 = 525, and 525 + 100 + 150 + 125 - 180 = 720.
Island 1: C = 40 + 0.5 * 450 = 265, and 265 + 80 + 100 + 180 - 125 = 500.
Input: countries = [isle(50, 0.8, 100, 100, 150, 0.2), isle(30, 0.6, 40, 80, 90, 0.1),
isle(20, 0.5, 0, 60, 40, 0)],
shares = [[0, 0.5, 0.5], [0.25, 0, 0.75], [0.5, 0.5, 0]]
Output: [579.240506329114, 467.8481012658228, 426.0253164556962]
Explanation: island 2 imports nothing (its row of shares is never used), but it sells to both others.
Constraints
- answers are compared with a tolerance of
1e-6; do not round - plain Python only (no numpy)
Goals
- Write each economy's equilibrium as a linear equation that involves its partners' outputs
- Solve a small linear system by elimination written out by hand
- See that one economy's imports are another's exports, so outputs are decided together