HHC 2016 RPL Programming Contest
09-21-2016, 12:10 AM
Post: #21
 DavidM Senior Member Posts: 768 Joined: Dec 2013
RE: HHC 2016 RPL Programming Contest
(09-20-2016 12:23 PM)Gene Wrote:  Winning solution at HHC 2016 came from Roger Hill at 56.5 bytes...

Congratulations to Roger for this winning entry! It appears that both Roger and Juan used a similar approach with slightly different steps, but Roger's was a tad smaller. I made an attempt to translate this same algorithm to a SysRPL implementation, but the smallest I could achieve was still slightly larger than 3298's at 42.5 bytes:

Code:
::    ZERO    OVERLEN$#1+_ONE_DO (DO) OVERINDEX@ SUB$1# #>CHR       3PICKSWAP       ONE POSCHR       INDEX@       SWAP#-       #MAX    LOOP    SWAPDROP    UNCOERCE ;

...and with apologies to 3298, I made an attempt at converting his/her SysRPL code to the closest thing I could manage in UserRPL. There are a couple of variances in how it operates (mostly due to there not being anything like POSCHRREV in UserRPL -- I had to use SREV to even get close), but you can still step through the code to get the gist of the basic algorithm. The code size still came in at a respectable 71.5 bytes, despite the shenanigans required to emulate POSCHRREV. I'm sure this would have been a contender if a UserRPL "POSREV" had existed. It requires a calc with lib 256 attached for the SREV command:
Code:
\<<   0 1 PICK3 SIZE   START     OVER     DUP     TAIL 4 ROLLD     SREV     ROT     HEAD     OVER SIZE UNROT     POS     -     MAX   NEXT   NIP \>>

I've enjoyed seeing everyone's results!
09-21-2016, 11:42 AM
Post: #22
 3298 Member Posts: 111 Joined: Oct 2014
RE: HHC 2016 RPL Programming Contest
(09-21-2016 12:10 AM)DavidM Wrote:  I made an attempt to translate this same algorithm to a SysRPL implementation, but the smallest I could achieve was still slightly larger than 3298's at 42.5 bytes:
Nosy gave me a handy routine you could use to get your size down to mine. At 13FD8 there is this small secondary;
Code:
:: ONE POSCHR ;
It's apparently unnamed, so I cannot guarantee that it's present on all ROM versions, but I'd expect most people are running 2.15 by now, which is the version I found this on. So replace the two commands ONE POSCHR by the single command PTR 13FD8 and enjoy a 40-byte solution! As a bonus, you have the same option to reduce its size further at the cost of usability (removing the UNCOERCE).

(09-21-2016 12:10 AM)DavidM Wrote:  ...and with apologies to 3298
What for? I posted code on a public forum without any copyright notice, so it's meant to be read, understood, used, and modified. This wasn't quite the kind of modification I expected (that would have been some more size optimization), but it's perfectly fine. Such a little snippet isn't worth putting a copyright on anyway. You even beat my own UserRPL translation by several commands.

About NIP: I think that's a Forth thing. As that's another important language in reverse polish notation, it's kind of expected RPL borrows some Forth concepts. Another example: The Forth equivalent of a FOR...NEXT is DO...LOOP, and in SysRPL they are - surprise! - written as DO...LOOP. Or even more basic, a Forth program is delimited by colon and semicolon. SysRPL just doubles the colon, possibly because on RPL.machines you usually get colons in pairs (for tagged objects).
09-21-2016, 02:14 PM
Post: #23
 DavidM Senior Member Posts: 768 Joined: Dec 2013
RE: HHC 2016 RPL Programming Contest
(09-21-2016 11:42 AM)3298 Wrote:  Nosy gave me a handy routine you could use to get your size down to mine. At 13FD8 there is this small secondary;
Code:
:: ONE POSCHR ;

When I was scanning through the code to optimize it, I focused on that very sequence thinking that it was a very obvious choice for a "combo" command. I was surprised it wasn't already a published.

Thanks for the reminder that Nosy can search for references to a command -- I had forgotten that feature.
09-22-2016, 12:43 AM
Post: #24
 Juan14 Junior Member Posts: 34 Joined: Jan 2014
RE: HHC 2016 RPL Programming Contest
Like everybody else, I sure have fun programming and I learned something, thanks DavidM.
 « Next Oldest | Next Newest »

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