Post Reply 
HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
09-14-2022, 12:47 PM
Post: #32
RE: HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
(09-14-2022 01:00 AM)David Hayden Wrote:  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.

I look forward to your revisions, David! We had a similar approach, so of course I think yours is great. Smile
Code:
@ Size: 180.0 bytes, CRC: 31DCh

\<<
  @ reversing subroutine
  \<<
    ""                        @ initial result is empty
    WHILE
      OVER                    @ continue while given quotient > 0
    REPEAT
      SWAP 10 IDIV2           @ pop the last digit from current value
      ROT SWAP +              @ append the digit to the result
    END
    NIP STR\->                @ drop final quotient, convert string to result
  \>> \-> r

  \<<
    0 SWAP                    @ loop counter
    DO
      DUP r EVAL              @ determine increment
      +                       @ add increment to current value
      SWAP 1 + SWAP           @ increment loop counter
    UNTIL
      OVER 50 >               @ >50 attempts?
      OVER 1E12 \>= OR        @ value out of range?
      { DROP2 0 DUP 1 }       @ zero out result and abort
      { DUPDUP r EVAL == }    @ otherwise check for desired result
      IFTE
    END
  \>>
\>>

I can't recall if the 49 supports IDIV2, so this may be limited to the 49g+/50g. Additionally, this version gains 8 bytes if you happen to transfer it to a calculator set to approximate mode due to the size differences in the numeric constants.

@Gene: thanks for posting, and especially for putting up with the requests for clarification. While they may be a pain, it's important to know what is and isn't allowed. This is especially true when a few bytes/nibbles here and there can make all the difference.
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 - DavidM - 09-14-2022 12:47 PM



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