# prize35-7 Exercise 1: feeding zones of three woodland birds and how much they overlap zones = ["ground", "low", "middle", "high", "canopy"] use = { "Bird X": [0.40, 0.30, 0.20, 0.10, 0.00], "Bird Y": [0.05, 0.25, 0.40, 0.25, 0.05], "Bird Z": [0.00, 0.05, 0.15, 0.30, 0.50], } def overlap(a, b): return sum(min(p, q) for p, q in zip(use[a], use[b])) def report(): names = list(use) worst = None for i in range(len(names)): for j in range(i + 1, len(names)): o = overlap(names[i], names[j]) print(f"{names[i]} + {names[j]}: {o:.2f}") if worst is None or o > worst[0]: worst = (o, names[i], names[j]) print(f"strongest competitors: {worst[1]} and {worst[2]} ({worst[0]:.2f})") report() print("--- Bird Y shifts up to avoid Bird X ---") use["Bird Y"] = [0.00, 0.10, 0.30, 0.35, 0.25] report() # Output: # Bird X + Bird Y: 0.60 # Bird X + Bird Z: 0.30 # Bird Y + Bird Z: 0.50 # strongest competitors: Bird X and Bird Y (0.60) # --- Bird Y shifts up to avoid Bird X --- # Bird X + Bird Y: 0.40 # Bird X + Bird Z: 0.30 # Bird Y + Bird Z: 0.75 # strongest competitors: Bird Y and Bird Z (0.75) # Reading it: Birds X and Y share the middle zones most (0.60), so they compete hardest. When Y moves up to escape X, # overlap with X falls to 0.40 but Y now crowds Z (0.75). Shifting a niche does not remove competition, it moves it; # only a real gap in resource use, like X (ground) and Z (canopy) at 0.30, gives strong separation.