Post Reply 
HHC 2015 RPN programming Contest is now open
09-29-2015, 03:48 PM (This post was last modified: 09-29-2015 07:42 PM by David Hayden.)
Post: #45
RE: HHC 2015 RPN programming Contest is now open
[EDIT: Fixed the byte count - Thanks Werner]

Okay, here is a version that seems to work. It uses the stack and flags 01-06. The code assumes that the flags are cleared at the start (my interpretation of the "assume default settings" rule) and it clears them at the end (as required for multiple runs). There is no call to SORT. In my experience, the only time you really need to sort data is for human consumption.

23 steps and 45 bytes, assuming that I can get away with a RTN at the end instead of an END.

Code:
01 LBL RR

# Set flags 1-6 corresponding to the contents of registers 1-5
# e.g., if R01 contains 5, set flag 05
02 5        # 1 byte
03 LBL 01    # 1 byte
04 RCL IND X    # 2 bytes
05 SF IND X    # 2 bytes?
06 X<>Y     # 1 byte
07 DSE X    # 2 bytesG
08 GTO 01    # 2 bytes
# Note that X=0 when you exit this loop. If there's a short
# straight, I'll leave it.

# Now compute the result into flag 03, clear the flags along the way
# You have a short straight if F3 & F4 & (F1&F2 | F2&F5 | F5&F6)
# Which is the same as  F3 & F4 & (F2 & (F1 | F5) | F5&F6)

09 FC?C 04
10 CF 03    # F3 = F3&F4
11 FS? 05
12 SF 01    # F1 = F1|F5
13 FC?C 01
14 CF 02    # F2 = F2&(F1|F5)
15 FC?C 06
16 CF 05    # F5 = F5&F6
17 FS?C 05
18 SF 02    # F2 = F2&(F1|F5) | F5&F6
19 FC?C 02
20 CF 03    # F3 = F3&F4 & F2&(F1|F5) | F5&F6

# X contains 0.0 as noted above. Change it to 1 if
# F03 is clear
21 FC?C 03
22 1
23 RTN
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HHC 2015 RPN programming Contest is now open - David Hayden - 09-29-2015 03:48 PM



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