With the help of the Stack Overflow community I\'ve written a pretty basic-but fun physics simulator.
You should use space partitioning to solve this problem.
Read up on Binary Space Partitioning and Quadtrees