Post Reply 
HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
09-14-2022, 01:00 AM (This post was last modified: 10-04-2022 05:44 PM by David Hayden.)
Post: #31
RE: HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
Here is my winning RPL entry. It can definitely be improved but I ran out of time. It could be restructured so it only reverses the number once. That would mean the list that reverses could be inline.

I'll try to clean it up and post a followup to show what I'm talking about.

185 bytes. #31E0h
Code:
«  
   {                       @ Function to reverse digits
     0. SWAP
     WHILE
          DUP
     REPEAT                @ reversedNum oldNum
           10. IDIV2       @ IDIV2 gives quotient and remainder
           ROT
           10. * +
           SWAP
     END
     DROP
   }
   
   0. ROT
   DO
       @ Stack is L1:counter L2:num
       SWAP 1. + SWAP      @ increment counter
       DUP
       4. PICK EVAL        @ reverse the digits
       +                   @ num + reverse(num)
   UNTIL
       @ Adjust results if resultŠ1E12 or counter>50
       DUP 1E12 ≥          @ result ≥ 1E12
       PICK3 50. >          @ counter > 50
       OR
       IF
       THEN
           DROP2
           0. DUP          @ So the UNTIL ends with the right stuff
       END
       DUPDUP              
       5. PICK EVAL        @ reverse number
       ==                  @ Break out of loop if num == reverse(num)
   END
   ROT DROP
»
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL - David Hayden - 09-14-2022 01:00 AM



User(s) browsing this thread: 6 Guest(s)