HHC 2021 Programming Contests - Surprise !
|
10-04-2021, 02:21 AM
Post: #7
|
|||
|
|||
RE: HHC 2021 Programming Contests - Surprise !
Here is my 40-byte program that won the RPN contest.
The program just counts up from the input number to find the first palindrome. To detect a palindrome, I reverse the digits, which can be done with very little code, and then compare the reversed number to the original. Speed wasn't a contest criteria, except that the code couldn't appear to be in an infinite loop. By counting up by ones, I ran the risk of it taking too long, so I submitted to code on a DM42 for maximum speed and hoped that none of the test cases would take too long. To reverse the digits of the original (old) number, I start with a new number of zero. Then in a loop do: digit := old MOD 10 new := 10*new + old old = (old-digit) / 10 For example, with an input number of 1234, igoes like this: Code: Iteration old new Here's the code. R01 = old number R02 = new number R03 = current candidate for a palindrome Code: 01 LBL "PAL" // program must be called PAL |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)