[VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
|
09-29-2022, 09:24 PM
Post: #1
|
|||
|
|||
[VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
Hi, all, After passing with flying colors the first part of your job application evaluation (the infamous "DEF FN Hell" part,) now the Human Resources manager, Ms. Lovejoy, mercilessly inflicts a new programming task upon those applicants who survived, namely asking them to create a simple three-liner strictly according to the following specification: The BASIC program (for a bare-bones HP-71B) must first (1) perform some initialization, ask for a real value x and force it to the range [1..100], then (2) it must display on a single line the values of
Your finished program must produce the following five test sample runs (plus "OK"), roughly tabulated here as follows for clarity's sake (the values should be output exactly as shown, the spacing is just indicative):
>RUN -> ? PI/2 [ENDLINE] -> 1.571 1.0 -5.1034E-12 -195948537906. 5.262060 >RUN -> ? 13 [ENDLINE] -> 13.000 0.4 0.9074 0.5 442415.956958 >RUN -> ? 30 [ENDLINE] -> 30.000 -1.0 0.1543 -6.4 1.068647E13 >RUN -> ? 51*PI/2 [ENDLINE] -> 80.111 -1.0 -3.9728E-11 25171429518.9 6.188666E34 Best of luck with your job application ! V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
09-30-2022, 02:58 PM
Post: #2
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
OK, I have one solution.
99 bytes for the 3 lines, passes the test cases. As often with exam-type problems, carefully read the problem and promptly eliminate potential solutions that can't work to concentrate on solutions that may. Can we find a shorter one? Not sure there are alternative solutions. J-F |
|||
09-30-2022, 08:07 PM
(This post was last modified: 09-30-2022 08:11 PM by C.Ret.)
Post: #3
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
Hi there,
It doesn't have to be a coincidence; my solution is also exactly 99 bytes. I really had a little trouble fitting everything into this line 2. I almost gave up. Simply filling in the dotted lines is not enough. But with a good shoehorn or a little trick consisting of a few additions and an omission... it's fine!! |
|||
09-30-2022, 10:04 PM
Post: #4
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
.
Hi, J-F and C.Ret, J-F Garnier Wrote:OK, I have one solution. 99 bytes for the 3 lines, passes the test cases. C.Ret Wrote:It doesn't have to be a coincidence; my solution is also exactly 99 bytes. By sheer coincidence, my original solution is 99 bytes too !! Might it be the case that all three solutions are essentially identical ? I'd suggest to delay posting solutions until Monday or Tuesday, just in case either we or someone else concocts a shorter one or some novel ideas. Thanks for your interest and best regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
10-03-2022, 11:31 AM
Post: #5
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
Hello HP-71B users/fans/experts,
This challenge is not that difficult, let me give one more hint: the solution is in the problem statement, what is to do is to implement it in a single BASIC line - a single DISP but not necessary a single statement. I believe the solution is unique, so if you follow the right track - knowing that the solution exists - you will for sure find it, it's a matter of logic (and a little bit of HP-71 BASIC knowledge, but not so much), just don't give up! J-F |
|||
10-04-2022, 07:22 AM
Post: #6
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
Since there are no last-minute candidate for the job, I will give my answer now.
The idea is, as requested, to use the FIX display mode. As a single DISP is allowed, a way to execute a FIX command before each argument is needed, and a user-defined-function will do it. Then the problem is just to fit everything in one line: 2 DISP FNF(3)+X,FNF(1)+SIN(X),FNF(4)+COS(X),FNF(1)+TAN(X),FNF(6)+LN(X)+EXP(X) @ DEF FNF(N) @ FIX N @ END DEF To enter the line, the spaces (except the first one after the line number) and the "DISP" string must not be typed, using the HP-71 implicit DISP feature - the only real trick needed here. J-F |
|||
10-04-2022, 08:42 PM
Post: #7
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
.
Hi, all, Thanks to J-F Garnier and C.Ret for their interest in this mini-challenge, time for a wrap up. J-F's solution is: J-F Garnier Wrote:As a single DISP is allowed, a way to execute a FIX command before each argument is needed, and a user-defined-function will do it [...] which, as foreshadowed, it's virtually identical to my original solution, which is: 2 DISP FNF(3)+X;FNF(1)+SIN(X);FNF(4)+COS(X);FNF(1)+TAN(X);FNF(6)+LN(X)+EXP(x) @ DEF FNF(N) @ FIX N @ END DEF the only difference being that J-F uses "," to separate the items while my OP uses ";", which results in a more compact output. Both solutions are 99 bytes long. C.Ret Wrote:Simply filling in the dotted lines is not enough. But with a good shoehorn or a little trick consisting of a few additions and an omission... it's fine!! Let's see C.Ret's solution to ascertain whether it's also identical to the ones above, which seems likely. The omission he mentions is probably the implicit DISP while entering the line. The idea for this mini-challenge was to let HP-71B users to further realize that
Thanks and regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
10-06-2022, 05:45 AM
Post: #8
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
Thanks Valentin for your inspiring problems (and detailed solutions) - and all others that share information and inspires!
It was many years since I was (?) a real 71B addict, and I was totally lost on this second assignment (looking for a trick using IMAGE instead of user defined functions ... ) but I never managed to cram it in to one line ... As a programmer I always have liked these kinds of problems - and the gained knowledge helps me in all kinds of other assignments. The better one knows the landscape - the more you can gain from the map! It has nothing to do with writing obfuscated code, rather writing solid code, avoiding pitfalls and using the available resources in the best way! Looking forward to similar assignments and challenges! Best regards, Thomas (7397)[134] [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] |
|||
10-06-2022, 02:17 PM
Post: #9
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
.
Hi, ThomasF, (10-06-2022 05:45 AM)ThomasF Wrote: Thanks Valentin for your inspiring problems (and detailed solutions) - and all others that share information and inspires! Thanks to you for your appreciation. I now I always say the same but there are only so many ways to express my thanks and I always mean it. Quote:[...] I was totally lost on this second assignment (looking for a trick using IMAGE instead of user defined functions ... ) but I never managed to cram it in to one line ... Hehe, that was pretty much my intent, that's why I put words like "image" and "using" in my OP in a subliminal way, to make people think about considering USING and IMAGE statements from the get-go. I don't think there's a solution using IMAGEs. One might try something like this and attempt to fine-tune it:
Quote:As a programmer I always have liked these kinds of problems - and the gained knowledge helps me in all kinds of other assignments. The better one knows the landscape - the more you can gain from the map! It has nothing to do with writing obfuscated code, rather writing solid code, avoiding pitfalls and using the available resources in the best way! I fully concur, couldn't say it better myself. Quote:Looking forward to similar assignments and challenges! Well, yesterday I just posted SRC #012a - Then and Now: Probability , the first of a number of non-trivial modern problems to be solved using exclusively vintage HP calcs, not the intended laptops. Most of them require solid programming abilities, and I'll supply nice HP-71B solutions for all of them. You might want to develop and post your own as well, it'll be great fun ! Thanks again and regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
10-08-2022, 01:38 PM
(This post was last modified: 10-08-2022 02:07 PM by C.Ret.)
Post: #10
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
Hello all,
My final version is exactly that of Valentin because like him I used semicolons for a more compact display. 2 DISP FND(3)+X;FND(1)+SIN(X);FND(4)+COS(X);FND(1)+TAN(X);FND(6)+EXP(X)+LOG(X) @ DEF FND(N) @ FIX N @ END DEF And like Jean-François, to enter this line you must omit typing the spaces between the key words and also typing DISP which will be added automatically by the HP-71B. It is precisely this omission that I alluded to in my previous post. Additions are more difficult to explain. But that's also what's most exciting. As I said before, I had a lot of trouble finding this solution and I almost gave up. The easiest thing for me is to tell you the whole story in the correct order. As usual, I started by reading the statement very quickly without paying attention to the details. Like Thomas, I went immediately to a formatting solution using the operators of the IMAGE command. In spite, having read that everything had to be put on line 2, I actually went head-on into a solution using a DISP USING ... Quickly I get a program a line resembling the one proposed above by Valentin: 2 DISP USING '9DZ.3D,11DZ.DX,8DZ.4D,11DZ.D,6DZ.6D';X,SIN(X),COS(X),TAN(X),EXP(X)+LOG(X) Well immediately I see that it's wrong, because I'm not getting the right results and a lot of error warning messages for large numbers. This is then I read the statement more carefully and see what is expected when the values are too low or too high... I then plan to format the result using a very complex user function that takes two arguments and returns a string. I get a DISPlay part already taking almost all available space on line 2: 2 DISP FND$(X,3);FND$(SIN(X),1);FND$(COS(X),4);FND$(TAN(X),1);FND$(EXP(X)+LOG(X),6) At first and hoping to be able to put all the code on line 2 after having found an optimization, I add lines 10 to 19 at the end of the program to put the definition of my FNF$(V, D) function. It's a nice function full of tests IF THEN ELSE statements, etc. that manipulates character strings to form integer part, fractional part and possibly the exponent depending of the number value to display. I will spare you the details of the 8 lines of code for this function. It is obvious that I went to a dead end, never such a structure will be able to enter the rest of the space available on line 2. So I need to find a trick. For everything to fit on line 2, there must necessarily be a way. Like using something that this wonderful HP-71B does naturally. That's when I found this on page 280 of my reference manual where syntax and usage of the STR$ function is explain: Quote:Format d'affichage à décimale fixe (FIX). La valeur est affichée en étant arrondie à n positions au-delà du signe décimal, où n est spécifié par FIX n. The translation is also on page 280 of the English Reference Manual, but it is also almost word for word what is specified in Valentin's statement: I therefore immediately plan to use the STR$() instruction to format my values and my display function FND$ length goes from 8 lines to one single line: 10 DEF FND$(V,D) @ FIX D @ FND$=STR$(V) @ END DEF This compact my function nicely, but still not everything is fitting in the single line 2. I must be doing something unnecessary. As it can't be the FIX n, it has to be related to the use of the STR$(). And yes! On page 82 of the same manual the operation of DISP is explained and it's said that DISP displays numbers according to the FIX n format exactly as the STR$() instruction does. It clicked in my little head. 2 DISP FND(X,3);FND(SIN(X),1);FND(COS(X),4);FND(TAN(X),1);FND(EXP(X)+LOG(X),6) ... 10 DEF FND(V,D) @ FIX D @ FND=V @ END DEF Still too long, I certainly have to avoid repetition of arguments or affectations such as FND=V, etc. So, a shorter function with a single argument definition results: FND(N) @ FIX N @ END DEF I then erased the superfluous and prohibited lines and reentered the whole line 2. Everything entered in but with the shoehorn, ie without any spaces or the initial DISP. 2 DISP FND(3);X;FND(1);SIN(X);FND(4);COS(X);FND(1);TAN(X);FND(6);EXP(X)+LOG(X) @ DEF FND(N) @ FIX N @ END DEF Unfortunately, this does not show the expected results but something like: [RUN] ?_ SQRT(5) [END LINE] 0.000 2.236 0.0 0.8 0.0000 -0.6173 0.0 -1.3 0.000000 10.161188 [END LINE] OK > The solution is finally to replace the semicolons after each call to the FND function by an addition sign, which causes the unwanted zeros to disappear from the display. 2 DISP FND(3)+X;FND(1)+SIN(X);FND(4)+COS(X);FND(1)+TAN(X);FND(6)+EXP(X)+LOG(X) @ DEF FND(N) @ FIX N @ END DEF Ah! What a challenge! That's not going to tarnish Valentin's reputation. I gave myself completely! And for once I found something decent. In any case, a thousand thanks, I really appreciate this type of exercise, even if it takes up a lot of my leisure time. |
|||
10-09-2022, 11:37 PM
Post: #11
|
|||
|
|||
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
.
Hi, C.Ret, (10-08-2022 01:38 PM)C.Ret Wrote: My final version is exactly that of Valentin because like him I used semicolons for a more compact display. Yup, as expected all three posted solutions are essentially identical. I don't think a significantly different one exists. This is a rare occurrence, usually some latitude is possible. Quote:The easiest thing for me is to tell you the whole story in the correct order. Wow, such an enthralling read, thank you very much for your time and effort in sharing with us your thought processes and tries while solving the challenge, this is exactly the kind of feedback I crave for; much appreciated and thanks a lot for it ! Quote:Ah! What a challenge! That's not going to tarnish Valentin's reputation. I gave myself completely! And for once I found something decent. In any case, a thousand thanks, I really appreciate this type of exercise, even if it takes up a lot of my leisure time. My sincerest congratulations for your success and thank you very much for your appreciation, I relly hope it was worth your while. 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)