Trouble in the last day

The game started to use 95% of my CPU after implementing an algorithm that is crucial to the gameplay. Now it's the last day, and I'll have to find the issue, and optimize it.