Post Reply 
[VA] HP-71B Mini-challenge: Qualifying for a job
09-20-2022, 03:59 PM
Post: #26
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
  
Hi, all,

Thanks to all of you who expressed interest in my HP-71B mini-challenge, namely J-F Garnier, C.Ret, ThomasF, KeithB, Dave Britten, rprosperi and Maximilan Hohmann, and most special thanks to those who provided code and analysis, much, much appreciated. Smile

J-F Garnier Wrote:
Quote:1 DEF FNZ @ DEF FNO=1

I'm starting to wonder if this was a deliberate trap set by Valentin. Smile

Indeed it was !. From the very start, I wanted to mislead would-be solutioners into stumbling upon this 92-byte decoy one-liner:
    1 DEF FNS(N) @ S=0 @ FOR I=1 TO N @ S=S+RND @ NEXT I @ FNS=S @ DEF FNG=FNS(8)-4 @ DEF FND=IP(RND*6+1) @ DEF FNZ @ DEF FNO=1
which must be entered without any spacing (and thus will later give a WRN: Line too long if attempting to edit it) as it requires exactly the maximum 95-char command line length. Some notes about it:
  • +INX can't be used instead of -4 because the line would then exceed 95 characters so it wouldn't fit in just one line.
      
  • IP(RND*6+1) can't be replaced by CEIL(RND*6) because (although extremely improbable) RND can return an exact zero value and then CEIL(RND*6) would evaluate to 0, which is not a valid die value.
      
  • FNS doesn't use recursion to compute the sum of the N random values but it uses simple iteration instead, which is faster and takes a very small, fixed amount of RAM. Initially I was intent in making recursion unusable in the solutions by simply including something like this as a sample run:

             >RANDOMIZE 1 @ FNS(100000) -> 49948.1804242

    which gives no problem to the iterative definition but would be totally unfeasible for the recursive definition, which would simply result in an Insufficient memory error. However, I liked the recursive definition and wanted people to find it out and use it in their solutions so I didn't include such large-N sample runs, in order to make it viable.
      
  • Finally, the trap. As written, the one-liner decoy would work Ok and be a correct solution IF no other executable code follows it. It seems to work perfectly, but there's an END DEF statement missing (actually, two) and the moment you add additional code after it (say, 2 DISP "Main program initialization follows ..."), your're going to encounter incorrect, unexpected behaviour, as some of you did.

    To ensure that such puzzling behavior was bound to be encountered I included this line in my OP:

      "She also mentioned that eventually your code would be immediately followed by some main-program initialization code written by another applicant."

    thus turning into non-solutions the decoy one-liner and any other solutions lacking the necessary END DEF statement(s) required by multi-line user-defined functions followed by arbitrary executable code.

That was the trap and many of you fell for it though, clever people that you are, you eventually analyzed it all and came to the right conclusions and correct solutions. Well done, congratulations ! Smile

As for my original solution, it's a 92-byte affair virtually identical to J-F Garnier's (who really nailed it) and other people's as well, namely:
    1 DEF FNS(N) @ IF N>0 THEN FNS=FNS(N-1)+RND
    2 END DEF @ DEF FNG=FNS(8)+INX @ DEF FND=IP(RND*6+1) @ DEF FNZ=0 @ DEF FNO=1
the only "difference" being that I used IP(RND*6+1) while J-F used IP(1+RND*6). Also, as explained above for the decoy one-liner, in purity the IP(...) can't be replaced by CEIL(RND*6), which would shorten the solution by 2 bytes, lest you'll get a 0 die throw once in a while, namely after 500-billion simulated throws on average ! Smile

That's all. Thank you very much for your interest, appreciation, analysis and solutions, I really hope you enjoyed it all and if furthermore you learned something new, so much the better. But don't think that your application process is over, just wait for Part 2 to be posted soon, stay tuned !

Best regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] HP-71B Mini-challenge: Qualifying for a job - Valentin Albillo - 09-20-2022 03:59 PM



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