Post Reply 
HHC 2015 RPN programming Contest is now open
10-07-2015, 12:41 AM (This post was last modified: 10-07-2015 12:44 AM by Sylvain Cote.)
Post: #95
RE: HHC 2015 RPN programming Contest is now open
It took me 6 versions (between 40 and 45 bytes) before being able to come up with a version under 40 bytes.

Code:
CAT"1
LBL`RR
END         38 BYTES

Code:
BB LL Code          Comment
-- -- ------------- ------------------------
05 01 LBL "RR"      Entry point
02 02 5             Loop #1 start index
01 03 LBL 01        Loop #1 top
02 04 RCL IND X     Get register value specified in X
02 05 SF IND X      Set flag specified in X
01 06 RDN           Get back loop index
02 07 DSE X         Decrement index and skip if zero
01 08 GTO 01        Go back loop #1 top
02 09 FS? 05        If flag 5 is set (see comment 3)
02 10 SF 01         set flag 1
02 11 4             Loop #2 start index
01 12 LBL 02        Loop #2 top
02 13 FC? IND X     If flag cleared
01 14 GTO 03        we leave, it's not a sequence
02 15 DSE X         Decrement index and skip if zero
01 16 GTO 02        Go back loop #2 top
02 17 1             We have a sequence of 4  :-)
01 18 STOP          Stop the program
01 19 LBL 03        Error!
02 20 0             We do not have a proper sequence
03 21 END           End of the program

Resources ...
Regs.: 1 to 5 with values sets before running this program
Flags: 1 to 5 and need to be cleared before running this program
Prog.: 38 Bytes

Comments:
1) there is only two valid values 1234 and 2345
2) the flags 1 to 5 are set based on the values (1 to 5) found. I used flags to remove duplicates and the needed for sorting
3) because a sequence of four is a winner, if flag 5 is set, then I set the flag 1 and only the first four flags (1 to 4) is validated


Edit: Arrrg, I forgot the value 6, I will correct it and come back
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 - Sylvain Cote - 10-07-2015 12:41 AM



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