Post Reply 
HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
09-15-2022, 01:07 PM
Post: #36
RE: HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
(09-14-2022 12:47 PM)DavidM Wrote:  
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
  \>>
\>>

Here’s a version of your program with the subroutine on the stack, like David Hayden’s above:

Code:

@ # 92C9h, 171.5 bytes

« { ""
  WHILE OVER
  REPEAT SWAP 10 IDIV2 ROT SWAP +
  END NIP STR→ } 0 ROT
  DO DUP 4 PICK EVAL + SWAP 1 + SWAP
  UNTIL OVER 50 > OVER 1.E12 ≥ OR { DROP2 0 DUP 1 } { DUPDUP 5 PICK EVAL == } IFTE
  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 - Gerson W. Barbosa - 09-15-2022 01:07 PM



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