My implementation for this ran for minutes, but since I got the right answer, I'm fine with it. The visualization would help with optimization, though =)