This is not efficient at all. It took ~20mins to complete. At the very least, I could try to speed up the looped process, which was designed for comprehension rather than memory/CPU usage.
It's also possible this process has some kind of periodicity that could be leveraged to skip forward in the calculation?