1234321 is a palidromic number. Any number that is the same when written forwards or backwards is called a palindromic number.
The term palindromic number is derived from palindrome, which refers to a word, like level, that reads the same backward or forward.
Challenge: Fastest Palindromic Numbers LocatorYour challenge is to code a custom Delphi function with the following signature:
NumberOfPalindromes takes one parameter: maxNumber an int64 number. Your task is to locate all palindromic numbers from 1 to maxNumber and return the number of found palindromes as a result of the function.
function NumberOfPalindromes(const maxNumber : int64) : int64;
For example, if maxNumber is 100, the result is 18. Palindromic numbers are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99.
To test the speed of execution the TStopWatch - High Precision Timer class will be used.
Accepted Entries (so far)Here's the list of the accepted entries. 17 entries were accepted before initial results were published.
Note: the list is in the order of execution speed, with the best results on top.
Download ALL accepted entries project
950 nanoseconds by Philippe Guglielmetti WINNER - 10 "fame and glory" points! :) 1050 nanoseconds by Harry Stockx 2nd place - 10 "fame and glory" points! :) 1550 nanoseconds by Carlos Trevino 2nd place - 5 "fame and glory" points! Boris Novgorodov - 1680 nanoseconds Geoffrey Phillips - 3000 nanoseconds David Reed - 3630 nanoseconds Wim Adriaensen - 4200 nanoseconds Peter Schrooders - 83 milliseconds Jolka Spodziu - 329 milliseconds Mikael Eriksson - 417 milliseconds Fabricio Colombo - 2293 milliseconds Marius Van Loo - 3259 milliseconds Henk Van Loo - 3289 milliseconds Jaision Joseph - 4353 milliseconds Kaushalya Damitha Weerakooon - 4400 nanoseconds Pedro Tibiletti - 4404 milliseconds Willie Geldenhuys - 4489 milliseconds Simon Boylen - 6232 milliseconds Frank Bishop - 6414 milliseconds Keith Foster - 22141 milliseconds
Notice: since we already have a "winner", please submit your code ONLY if you have a faster algorithm.
Challenge CLOSED!Note: this challenge is closed. Several valid entries have been submitted before the challenge was closed and the winner(s) announced.
Delphi programming challenges / exercises are designed to help you refactor your old code to make it more efficient; get new ideas on how to code faster / better Delphi code; help you solve a particular Delphi programming task and of course: to have fun while coding in Delphi :)