Post Reply 
HHC 2014 Programming Contest
09-24-2014, 09:13 AM
Post: #1
HHC 2014 Programming Contest
Joe Horn posted the rules in a different thread.
They are worth linking to again here.

Anyway, on to the nitty gritty.

My first attempt for the 34S follows. The 34S has some advantages here. Date arithmetic and a built in primality tester. It isn't so good at long constants however, I almost wish I'd implemented merged constants which would save lots of steps. Oh well, too late for that now.

The four steps prepended with a minus sign can be removed trivially:
  • The initial label is obviously optional.
  • LBL 01 is a subroutine called from one place. Make that a BACK branch instead and the RTN+1 statements become a SKIP branch to the instruction after the LBL 03 position.
  • LBL 03 is a target of a single branch. Use a SKIP instead.
  • CLx is a visual indication that the program has finished, more for debugging than anything else.

That makes forty steps. Not a bad first stab at the solution but I very much doubt this is even remotely close to the minimal.


- Pauli


Code:
-    1  LBL A
     2          STO I           Need to seed this register to something small
     3          RCL X           Duplicate the input to give us a stopping value
     4          DEC X           Go back to December 31st of the previous year
     5          SDL 003                 this takes six steps and could probably
     6          # 123                   be improved.  We want (y-1)*10000+1231
     7          +                       which is 10000 y - 8769.  On the 34S
     8          SDL 001                 this takes the same number of steps
     9          INC X                   unless a short cut can be found
    10          RCL Y           Get our year back
    11          INC X           This time we go to Jan 1st of the following year
    12          SDL 004                 I.e. y * 10000 + 101
    13          # 101
    14          +
    15          CF 00           Clear our flag
    16          PRIME?
    17                  SF 00   But set it if Jan 1st is prime.
    18          GTO 03          Skip to the date decrementer

-   19  LBL 01                  Got a prime, check for twin
    20          FC? 00
    21                  STO I   Save if we've not had a prime before
    22          FC?S 00
    23                  RTN+1           and return one step ahead
    24          x[<->] I
    25          XEQ 02          Get previous value and display
    26          x[<->] I
    27          XEQ 02          Display current value
    28          RTN+1           Return with skip

    29  LBL 00                  Main loop check the date
    30          PRIME?
    31                  XEQ 01  If it is prime, do stuff
    32          CF 00           Not prime, clear our twin flag
-   33  LBL 03                  Step back a day
    34          SDR 004                 The 34S only has yyyy.mmdd not
    35          1                       the desired yyyymmdd.  Maybe in the 43S
    36          +/-
    37          DAYS+
    38          SDL 004
    39          x[>=]? Y        Check for loop termination
    40                  GTO 00
-   41          CLx             Visual indication of finished

    42  LBL 02                  Display if in range
    43          x>? Y
    44                  STOP    Use a PSE for less interaction
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HHC 2014 Programming Contest - Paul Dale - 09-24-2014 09:13 AM
RE: HHC 2014 Programming Contest - BruceH - 10-02-2014, 09:35 PM
RE: HHC 2014 Programming Contest - Jeff O. - 09-29-2014, 01:41 PM
RE: HHC 2014 Programming Contest - Jeff O. - 09-30-2014, 04:39 PM
RE: HHC 2014 Programming Contest - Jeff O. - 10-06-2014, 05:01 PM
RE: HHC 2014 Programming Contest - Jeff O. - 10-07-2014, 12:26 PM
RE: HHC 2014 Programming Contest - Werner - 10-03-2014, 07:35 AM
RE: HHC 2014 Programming Contest - C.Ret - 10-05-2014, 10:02 AM
RE: HHC 2014 Programming Contest - Werner - 10-05-2014, 08:02 PM



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