There is a discrepancy in results of this algorithm compared to the Pythonic one. Both algorithms work, but produce different results.