This is basically a semi-useful function that I am using to help me get my head around various programming languages.
It started simply in Python but I was curious to see how it worked in C++ to compare speeds. Believe it or not C++ was substantially quicker!
I then used it as a basis for ARM assembly language code which turned out to be a load slower than the C++, my best guess is because of horrendously, horrendously poorly optimised code.