I am learning programming, I know this has been asked many times, but I want the most efficient algorithm to achieve this in many different languages. I want it like this, i