How can I improve the speed of my algorithm, even by the slightest amount. For the reason I made this I don\'t actually care about speed in the slightest, but I\'m wondering