''' Prerequisite: This exercise builds on previous exercises where you implemented collisions between particles. **Exercise A:** Adapt your code to show at least 1000 particles of each type. Does your code still run at a decent speed? **Exercise B:** Find out which part of your code is responsible for the slowdown. Can you explain why? **Exercise C:** The NaNoPy package contains a method for simulating particle collisions more efficiently. Read the documentation for the `get_close_pairs` and `apply_to_close_pairs` functions. `get_close_pairs` gives you the indices of particles that are close to each other: ''' from NaNoPy import get_close_pairs xs = [10, 12, 200] ys = [10, 15, 300] for i, j in get_close_pairs(xs, ys, 20): print(i, j) ''' `apply_to_close_pairs` runs the function below it once for every close pair: ''' from NaNoPy import apply_to_close_pairs xs = [10, 12, 200] ys = [10, 15, 300] @apply_to_close_pairs(xs, ys, 20) def print_pair(i, j): print(i, j) ''' **Exercise D:** Upgrade your collision detection with one of the two functions. Note that the functions only check rough proximity. You still need to check the distance for particles that are close. **Explanation for speed-up:** Under most conditions, the functions provided in NaNoPy are faster than checking each particle distance at every step. This is because they first assign particles to smaller groups based on rough location, thereby avoiding unnecessary checks. '''