Optimizing an algorithm that's quadratic by design | Hacker News Reader