HHC 2016 RPL Programming Contest (HP-71B)
09-22-2016, 10:58 PM
Post: #1
 Valentin Albillo Senior Member Posts: 776 Joined: Feb 2015
HHC 2016 RPL Programming Contest (HP-71B)
Hi all:

Sorry to be so late but I just came back home from a 2-month unplugged summer vacation in the countryside and saw this HHC 2016 RPL challenge at the forum. I've completely refrained from reading the various threads so as not to spoil it for me and thus be able to give it a try in bare-bones HP-71B's BASIC (no ROMs or LEX files).

I quickly came to this 1-liner (6 statements, 50 bytes) solution:

1 INPUT S$@ M=0 @ FOR I=1 TO LEN(S$) @ M=MAX(M,I-POS(S$,S$[I,I])) @ NEXT I @ DISP M

>RUN
? HIPPOPOTAMUS [ENTER]
3
...

>RUN
? pablitoclavounclavito [ENTER]
15

which delivers the goods, it's easy to understand and works for any input, including lowercase or any other characters, as well as single characters and the null string.

I don't know how this compares lengthwise to the best RPL solutions (as I said, I haven't read the RPL threads) but seems to me this is as simple as can be, except for the fact that I've also produced another 50-byte solution (same length) which uses no string variable (S$), just the numeric variables I (for the index) and M (to keep track of the maximum distance). See if you can fathom how it's done (quite simple actually) ! 8-D Regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection 09-25-2016, 08:11 AM Post: #2  J-F Garnier Senior Member Posts: 562 Joined: Dec 2013 RE: HHC 2016 RPL Programming Contest (HP-71B) (09-22-2016 10:58 PM)Valentin Albillo Wrote: ... I've also produced another 50-byte solution (same length) which uses no string variable (S$), just the numeric variables I (for the index) and M (to keep track of the maximum distance).

See if you can fathom how it's done (quite simple actually) ! 8-D

Hi Valentin,

As always, your HP-71B solutions are compact, efficient ... and amazing!
For your 'nano-challenge' without string variable, may I suggest this way:

1 M=0 @ FOR I=1 TO LEN(DISP$) @ M=MAX(M,I-POS(DISP$,DISP$[I,I])) @ NEXT I @ DISP M To use it, type the string, DON'T press ENTER but RUN: >HIPPOPOTAMUS [RUN, not ENTER !] 3 >pablitoclavounclavito [RUN] 15 J-F 09-26-2016, 11:04 AM Post: #3  Valentin Albillo Senior Member Posts: 776 Joined: Feb 2015 RE: HHC 2016 RPL Programming Contest (HP-71B) . Hi, Jean-François: (09-25-2016 08:11 AM)J-F Garnier Wrote: As always, your HP-71B solutions are compact, efficient ... and amazing! Thanks a lot for your kind comment, much appreciated, but it was far too easy a challenge so no great merit on my part. Quote:For your 'nano-challenge' without string variable, may I suggest this way: 1 M=0 @ FOR I=1 TO LEN(DISP$) @ M=MAX(M,I-POS(DISP$,DISP$[I,I])) @ NEXT I @ DISP M

Correct. Your 'suggestion' is an exact copy (to the character) of the one I concocted. Of course I wouldn't expect any less of you ... 8-D
This technique (using DISP$) has at least 3 advantages over the S$ version:

1) No need to define or use a string variable to hold the input.

2) In use, you save one keystroke (only [RUN] instead of [RUN] and afterwards [ENTER]).

3) It allows for a much longer string as input. The S$version limits input to 32 characters maximum, which is the default length of not explicitly dimensioned string variables, while the DISP$ version allows the user to input as many as 96 characters maximum, i.e., three times as many.

The DISP\$ version is possible only because the HP-71B's BASIC implementation allows the substring operator [,] to work on any string expression, not just on string variables as was the case in simpler BASIC implementations such as the one for the HP-85, say.

Thanks for your interest in my 'micro-challenge' and for your perfect contribution.

Best regards.
V.
.

All My Articles & other Materials here:  Valentin Albillo's HP Collection

 « Next Oldest | Next Newest »

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