Post Reply 
[VA] HP-71B Mini-challenge: Qualifying for a job
09-14-2022, 04:00 PM
Post: #1
[VA] HP-71B Mini-challenge: Qualifying for a job
.
Hi, all,

Lately there's been an unusually large number of HP-71B-related threads and posts, which pleases me no end because I've always felt poor 71B is considered the 'ugly duckling' among the HP calc family. It's always been unjustly underappreciated, a niche model which barely registered in an essentially RPN/RPL community. It isn't even considered as a valid model to enter many challenges (not mine, mind you.) Sad

In the distant past, almost 40 years ago, this was well justified by the 71B's outrageous price which put it utterly out of reach for most people. For instance, where I live a bare-bones 71B (w/o any mass storage) was 5x-6x more expensive than the HP-41C, and I only could get my hands on one because of my contacts at local HP first, and then when I persuaded my company's boss to get one and lend it to me on a permanent basis (I still have it !)

However, nowadays there's a number of emulators which run on various OS, some free (Emu71/DOS, Emu71/Win), some not (go71b, but quite affordable,) providing the major convenience of running a virtual HP-71B on a portable device (smartphone, tablet), at speeds hundreds of times faster than the physical unit, with full memory (> 400 Kb RAM) and all ROMs (Math, JPC, ...) and LEX/BIN files available at no cost, so you can tackle and solve most math-related problems anywhere, even on the go.

Add to that its superb version of BASIC, only marred by no long variable names but enormously enhanced by the various ROMs providing IEEE math, complex number support, matrix operations, polynomial and generic rootfinders, numerical integration, FORTH, Assembler, Finance, etc., and with support for recursive multi-line user-defined functions and subprograms with their own environments separated from the main program and with parameter passing by value and/or reference, plus the great clarity and simplicity afforded by BASIC, and you've got what should have been a winner hands down back then (were it not for the unaffordable price) and which certainly deserves to regain its birthright now that price and availability are no longer an issue.

That said, and in order to help appreciate it better, all forum members - both new to the HP-71B and seasoned experts alike - can try and sharpen their claws and teeth by tackling this nice, simple, cute

HP-71B Mini-challenge: Qualifying for a job

On a bare-bones HP-71B, the Human Resources manager (who's checking out your qualification for the job you're applying to) asks you to write a BASIC program implementing the following five utility user-defined functions, namely:

      FNS(N)  Returns the sum of N random numbers generated sequentially
                by using the RND function
      FNG     Parameterless function, returns a pseudo-gaussian random number generated
                by adding up 8 random numbers (RND) and then subtracting the value 4
      FND     Parameterless function, returns a random throw of a die,
                i.e. an integer between 1 and 6
      FNO     Parameterless function, always returns One  (1)
      FNZ     Parameterless function, always returns Zero (0)

A sample use from the command line prompt would be:

      >DESTROY ALL @ STD @ RANDOMIZE 1

      >FNS(100)      ->   48.4961724443
      >FNG;FNG;FNG   ->   -.57175274691  -.95449301737  1.07825991612
      >FND;FND;FND   ->   5  5  3
      >FNO           ->   1
      >FNZ           ->   0

She also mentioned that eventually your code would be immediately followed by some main-program initialization code written by another applicant, and that in order to gauge your efficiency your program should be at most 92 bytes long (as reported by the CAT function,) lest you wouldn't qualify for the job.

Well. I hope you'll like this simple mini-challenge, surely an enjoyable way for you to practice your HP-71B BASIC skills. I'll post my original solution in a few days, so you've got plenty of time to go for it.

Waiting for your entries, best of luck with your job application ! Smile

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
09-14-2022, 05:14 PM
Post: #2
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
Nitpick:
IEEE Math was built in, not added by a ROM.
Find all posts by this user
Quote this message in a reply
09-14-2022, 07:02 PM (This post was last modified: 09-14-2022 07:54 PM by J-F Garnier.)
Post: #3
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-14-2022 04:00 PM)Valentin Albillo Wrote:  Lately there's been an unusually large number of HP-71B-related threads and posts, which pleases me no end [..]
Same here.
But I don't think the HP-71B is the 'ugly duckling' , it has its own and quite unique place in the HP calculator family.
The HP-75 owners may have good reasons to complain too ! The HP-75 is clearly an underappreciated machine!

Quote:In the distant past, almost 40 years ago, this was well justified by the 71B's outrageous price which put it utterly out of reach for most people. For instance, where I live a bare-bones 71B (w/o any mass storage) was 5x-6x more expensive than the HP-41C, and I only could get my hands on one because of my contacts at local HP first, and then when I persuaded my company's boss to get one and lend it to me on a permanent basis (I still have it !)
Quite the same here. I got my almost personal HP-71B on end of 1984 when I joined the Kristal company to develop HP-IL products.
I still have it too, with a pseudo-inventory sticker:
   
and it is still my main HP-71B.

Now back to the challenge (thanks for it!).
To my HP-71B friends: DON'T spoil the game by posting your solutions now, just post your score!
My current score is 114 bytes, and counting.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
09-14-2022, 08:26 PM
Post: #4
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
My feeling is that if IBM PC's (and clones) had not been adapted to instrument control so quickly, the HP-71 could have found a niche.
Find all posts by this user
Quote this message in a reply
09-14-2022, 08:35 PM (This post was last modified: 09-14-2022 08:43 PM by Dave Britten.)
Post: #5
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
Well I've got a 99-byte two-liner so far.

I really like the 71B version of BASIC, though I wish it could do two-letter variable names. And it could stand to have a bit nicer user interaction - messing around with DELAY and having to use functions like ERRM on the keyboard is a lot clumsier than Sharp's simple command interface and display handling. It's a very powerful machine, though!

EDIT: 90 bytes, two lines.
Visit this user's website Find all posts by this user
Quote this message in a reply
09-15-2022, 07:05 AM (This post was last modified: 09-15-2022 07:22 AM by C.Ret.)
Post: #6
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
Hi there,

It is with great pleasure that I participate in this mini-challenge on my real HP-71B (HP71:2CDCC JPC:E01 HPIL:1B ALARM:B DATA:B CLK:MS KBD:B MATH:1A ) . I didn't have any time to install an emulator, I'm in a hurry, I now have to quickly catch a train to go to work.

But, thanks to the indications given by Valentin and especially Dave, I arrived, according to the CAT instruction, at 88 Bytes while obtaining the following results:


>CAT
                       -> workfile BASIC 88 09/15/22 07:55
>DESTROY ALL @ STD @ RANDOMIZE 1
>FNS(100)
                       -> 48.4961724443
>FNG;FNG;FNG
                       -> -.5717527469 -.95449301737 1.07825991611
>FND;FND;FND
                       -> 5 5 3
>FNO
                       -> 1
>FNZ
                       -> 0
Find all posts by this user
Quote this message in a reply
09-15-2022, 07:23 AM
Post: #7
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-14-2022 08:35 PM)Dave Britten Wrote:  I really like the 71B version of BASIC, though I wish it could do two-letter variable names. And it could stand to have a bit nicer user interaction - messing around with DELAY and having to use functions like ERRM on the keyboard is a lot clumsier than Sharp's simple command interface and display handling. It's a very powerful machine, though!
The variable name limitation was for sure one of the main drawback of the HP Technical BASIC (series 70, HP-85). The limitation was removed on the HP-86/87 together with larger memory, but never on the Series 70 since this family stopped with the HP-71B.


Quote:Well I've got a 99-byte two-liner so far.
EDIT: 90 bytes, two lines.

OK, I got my 2-line, 90-byte solution too !
I can even reduce it to 89 bytes.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
09-15-2022, 07:39 AM
Post: #8
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-15-2022 07:05 AM)C.Ret Wrote:  But, thanks to the indications given by Valentin and especially Dave, I arrived, according to the CAT instruction, at 88 Bytes while obtaining the following results: [..]

Great !
Actually, I have a 87-byte solution that passes Valentin's test cases, but may crash for bad inputs so is quite bad programming :-)
Curious to see your solution now !

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
09-15-2022, 08:05 AM (This post was last modified: 09-15-2022 10:12 AM by C.Ret.)
Post: #9
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-15-2022 07:39 AM)J-F Garnier Wrote:  Actually, I have a 87-byte solution that passes Valentin's test cases, but may crash for bad inputs so is quite bad programming :-)


We must have very close solutions. My code certainly has the same type of defect. If an incorrect value is used, it leads to an "Insufficient Memory" error despite my machine's 64K RAM module.

In the meantime, I found a way to save two more bytes. But that doesn't correct the main flaw.


>CAT
                       -> workfile   BASIC      86   09/15/22 10:48
>LIST
                       -> ▓▒▓▓▓▒▓▓▓▓▓▒▓▒▓▓▓▒▓▓▓▒▓▒▓▓▓▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▓▒▓▓▓▒▓▓▓▓▓▓▒▓▒▓▓▒▓▒▓▓▓▓▒▓▓▓▓▓▓▓▓▓▓▓▓​▓▓▓▓
                       -> ▓▒▓▓▓▒▓▓▓▒▓▒▓▓▓▒▓▓▓▓▓▓▓▓▓▓▓▓


Oops!
LCD display failure; just to give everyone around the world a little more time to solve this new amazing Valentine's challenge

EDIT: Surprisingly, fixing the defect leads to a version that is 75 bytes. I expected three more than 86. In any case well below the threshold!
I now have a one-liner
>CAT
                       -> workfile   BASIC      75   09/15/22 11:00
>LIST
                       -> 1▒▓▓▓▒▓▓▓▓▓▒▓▒▓▓▓▒▓▓▓▒▓▒▓▓▓▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▓▒▓▓▓▒▓▓▓▓▓▓▓▓▓▓▓▓▒▓▒▓▓▓▒▓▓▓▓▓▓▒▓▒▓▓​▒▓▓▓(▓)▒▓▓▓▓▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓


EDIT2: I didn't use any instructions from the inserted modules of my machine.
On the other hand, this code is not editable (line too long) and must be placed at the very end of the program which will use these functions at the risk of not working correctly because something terminal is missing.
Find all posts by this user
Quote this message in a reply
09-15-2022, 10:30 AM
Post: #10
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
.
Hi, C.Ret,

(09-15-2022 08:05 AM)C.Ret Wrote:  [color=#808000]On the other hand, [...] must be placed at the very end of the program which will use these functions at the risk of not working correctly because something terminal is missing.

Could you specify what you mean by "something terminal is missing" ?

As per my OP, the HR manager clearly states that, I quote,

"eventually your code would be immediately followed by some main-program initialization code written by another applicant,"

so your code's workings can't depend on it being at the very end of the program, lest the initialization code which will follow it would be affected or even not work at all.

I know that in theory user-defined functions can be located almost arbitrarily in a program but the HR manager specifies that your code will be followed by some other code so it won't be at the very end, and who am I to discuss it with her ? Smile

To wit: If your solution depends on your code being at the very end of the program, then it's not a valid solution. That goes for everyone else's solutions.

Thanks for your interest and 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
09-15-2022, 11:38 AM (This post was last modified: 09-15-2022 11:41 AM by C.Ret.)
Post: #11
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
I omitt the final END DEF statement because it can't be at the end of the only line containing a conditional structure and need one extra line for it's own.
Without adding this missing second line, the whole following program will be part of the FNS definition !

Shade of me, bad bad practices...

...but I don.t ask for much per week, eat no more than two sandwiches per day and only need a few square feet clear in the back office to sleep.
Find all posts by this user
Quote this message in a reply
09-15-2022, 12:21 PM
Post: #12
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-15-2022 11:38 AM)C.Ret Wrote:  I omitt the final END DEF statement because it can't be at the end of the only line containing a conditional structure and need one extra line for it's own.
Without adding this missing second line, the whole following program will be part of the FNS definition !

This is what I understood. Now that you disclosed a lot, it may be time to post our best (valid) solutions. I will do tomorrow.

Quote:...but I don.t ask for much per week, eat no more than two sandwiches per day and only need a few square feet clear in the back office to sleep.

Don't do that for too long !

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
09-15-2022, 01:14 PM (This post was last modified: 09-15-2022 01:15 PM by Stefan_Titan2944A.)
Post: #13
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
Quote:But I don't think the HP-71B is the 'ugly duckling'

Same here - Sure, there are "sexy" HP calculators.
Nevertheless, HP71B has other qualities.

   
Find all posts by this user
Quote this message in a reply
09-16-2022, 06:10 AM (This post was last modified: 09-16-2022 06:34 AM by C.Ret.)
Post: #14
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-15-2022 12:21 PM)J-F Garnier Wrote:  Now that you disclosed a lot, it may be time to post our best (valid) solutions. I will do tomorrow.

The problem is that even my most successful version isn't quite perfectly valid. As I announced previously, it is 89 bytes (without line 10) and I would have needed a few more to correct a last and the very slight but undeniable pitfalls, which I leave these to you to discover by analyzing my most (valid) code:


>CAT                   -> workfile   BASIC      89   09/15/22 15:21
>LIST                   -> 1 DEF FNO=1 @ DEF FNZ=0 @ DEF FND=CEIL(6*RND) @ DEF FNG=FNS(8)-4 @ DEF FNS(N) @ IF INT(N) THEN FNS=RND+FNS(N-1)
                      -> 2 END DEF

                      -> 10 DISP TIME$ @ PAUSE



Line 1 cannot be edited directly because it is too long. To enter it, you must type the instructions without separating spaces, ie without using the preprogrammed key on the keyboard.

I colored in light blue the omissions of the faulty 75-byte version and the test-program line 10. The faults of this inadmissible version are effectively demonstrated by adding a beginning of the program serving as a test. We then realize that the calls to FNZ and FNS(n) display the time before returning any result because the instruction indicating the end of the definition is missing.

Nevertheless, these two lines are very interesting, and I greatly thank Valentin for this formidable challenge which is an opportunity to show the power of the HP-71B and its BASIC.

Indeed, in two lines appear the different types of user-function definitions;
  • with or without '=' sign,
  • in one or more lines,
  • a definition using another user function (which can be placed before the second),
  • a definition by recurrence,
  • ...

Many of these programmatic aspects are not allowed on other less powerful BASIC or other programming languages ​​(FORTH, PASCAL, ...) Not to mention runtime efficiency both for speed and memory consumption that results.

The downside of these optimizations is the regretful limitation in the names of variables deemed too short. But it's infinitely better than having only numbered and anonymous registers and so much faster than other BASICs allowing phantasmagorical and useless names of 32 characters!
Find all posts by this user
Quote this message in a reply
09-16-2022, 11:44 AM (This post was last modified: 09-16-2022 11:46 AM by J-F Garnier.)
Post: #15
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
Indeed, our solutions are very close, not really a surprise to achieve the target set by Valentin.

So here is my 2-line, 90-byte solution:

10 DEF FNS(N) @ IF N>0 THEN FNS=FNS(N-1)+RND
20 END @ DEF FNG=FNS(8)-4 @ DEF FND=IP(1+RND*6) @ DEF FNZ=0 @ DEF FNO=1

The main gain is to realize that END can be used in place of END DEF on the HP-71B.

As C.Ret, I considered saving 2 bytes by using the condition "IF N" instead of "IF N>0" that is equivalent for positive integer values of the argument N, but can lead to a crash (infinite recursion) in case of incorrect arguments.

I can save one more byte by changing:
DEF FNG=FNS(8)-4
to
DEF FNG=FNS(8)+INX
using the INX constant = -4, a trick I already used in other challenges (experience counts in that matter :-)
But it's quite inelegant and I will stick to my 90-byte version.

I'm still puzzled by the goal of the FNZ and FNO trivial functions, I don't see any way to make them simpler.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
09-16-2022, 11:53 AM
Post: #16
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
Mine ended up being nearly identical:

Code:
0001 DEF FNS(C) @ IF C>0 THEN FNS=FNS(C-1)+RND
0002 END @ DEF FNG=FNS(8)-4 @ DEF FNO=1 @ DEF FNZ=0 @ DEF FND=INT(RND*6)+1
Visit this user's website Find all posts by this user
Quote this message in a reply
09-17-2022, 06:14 AM (This post was last modified: 09-17-2022 06:15 AM by ThomasF.)
Post: #17
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-16-2022 11:44 AM)J-F Garnier Wrote:  I'm still puzzled by the goal of the FNZ and FNO trivial functions, I don't see any way to make them simpler.

Hi J-F,

You could eliminate 2 bytes by the following trick:

Code:
1 DEF FNZ @ DEF FNO=1

CAT gives 20 bytes compared to 22 by including "=0" ... Wink

Cheers,
Thomas

[35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X]
Find all posts by this user
Quote this message in a reply
09-17-2022, 07:23 AM (This post was last modified: 09-17-2022 07:27 AM by J-F Garnier.)
Post: #18
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-17-2022 06:14 AM)ThomasF Wrote:  You could eliminate 2 bytes by the following trick:
Code:
1 DEF FNZ @ DEF FNO=1

No, it's an illusion, it doesn't work as expected. Smile

See the explanations from C.Ret above.

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

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
09-17-2022, 09:05 AM
Post: #19
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-17-2022 07:23 AM)J-F Garnier Wrote:  
(09-17-2022 06:14 AM)ThomasF Wrote:  You could eliminate 2 bytes by the following trick:
Code:
1 DEF FNZ @ DEF FNO=1
No, it's an illusion, it doesn't work as expected. Smile

Hi again,

Hm, maybe I missed something?
I tried with your example, and rearranged it a bit (moved FNZ to the beginning):

Code:
0001 DEF FNZ @ DEF FNS(C) @ IF C>0 THEN FNS=FNS(C-1)+RND
0002 END @ DEF FNG=FNS(8)-4 @ DEF FNO=1 @ DEF FND=INT(RND*6)+1

0005 DEF FNG @ DEF FNT=5
0010 DISP TIME$ @ PAUSE

That worked fine, even when inserting line 5 and 10, sinced I expected the END at beginning of line 2 would act as a "DEF END", ie. executing "FNZ" will not display the time (only 0), but FNG sure will (show the time) but not FNT (will just show 5) ...

Cheers,
Thomas

[35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X]
Find all posts by this user
Quote this message in a reply
09-17-2022, 09:20 AM
Post: #20
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-17-2022 09:05 AM)ThomasF Wrote:  
Code:
0001 DEF FNZ @ DEF FNS(C) @ IF C>0 THEN FNS=FNS(C-1)+RND
0002 END @ DEF FNG=FNS(8)-4 @ DEF FNO=1 @ DEF FND=INT(RND*6)+1

0005 DEF FNG @ DEF FNT=5
0010 DISP TIME$ @ PAUSE

That worked fine, even when inserting line 5 and 10, sinced I expected the END at beginning of line 2 would act as a "DEF END", ie. executing "FNZ" will not display the time (only 0), but FNG sure will (show the time) but not FNT (will just show 5) ...

FNZ seems to work fine because you "opened" a multiline DEF structure on line 5. If you put any other code, or close your DEF FNG structure with END DEF followed by some code, that code will executed as part of the function FNZ.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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