Post Reply 
[VA] Short & Sweet Math Challenge #22: April 1st, 2018 Spring Special
04-01-2018, 09:08 PM
Post: #1
[VA] Short & Sweet Math Challenge #22: April 1st, 2018 Spring Special
 
Hi all,

After a mere 10-year hiatus here's again my super-duper S&SMC April 1st, 2018 Spring Special to welcome the new season and give you all a chance to put to good use both your favourite HP calculator and your programming ingenuity.

The thing is, I've always been very interested in primes and algorithms for factorization and primality tests of big numbers and recently computed the factorization of

      555555555555554444444444444443333333333333332222222222222222211111111111111

and proceeded to check it out with my trusty HP-71B (it checked OK!), so I got the idea of making some kind of primality testing the main subject of this S&SMC#22, plus assorted goodies. Read on !:

Notes :

Any HP model of your choice may be used but I'll suggest a Minimum Recommended Model (MRM) for each problem, which is the  minimum model I deem capable of solving it more or less comfortably. Obviously, using a more powerful model might make life easier and, conversely, using a less powerful model might succeed or not.

If you use an HP­41C/CX/CV you can also use any of these ROM: Math, Advantage, Card Reader, Printer. No  other ROM or extra routines allowed. If you use an HP­71B, you can also use any of these ROM: Math, HP­IL, JPC, STRNGLEX Lex file. No other ROMs or LEX files allowed.

Using a PC or any computing device other than a physical or emulated HP calculator is strictly disallowed. You can write your code in any language supported in any HP calc and it must run in that calc (i.e.: RPN, RPL, 71B BASIC, 71B FORTH, etc). Googling for the solutions is lame beyond belief, frankly.



The Challenge - Main Course:


[MRM: HP42S and up] Write code that takes as input any of the following six test numbers and simply outputs whether it's a prime or not (no need to compute or output its factorization if not prime). Your code might or might not work for some other arbitrary numbers of arbitrary length but it should definitely output the correct result for each of the following six test numbers:

      8082737769637879
      89698373657765787367698082737769
      677977807983738469788577666982
      7365778082737769847979
      677977807983738469658387697676
      7378686969688082737769

Your code must be as short and fast as possible, in that order. Within a few days I'll give a 72-byte solution for the HP-71B (an User-Defined Function) and a 39-byte solution for the HP42S (a program) but meanwhile let's see what you can do.


The Challenge - 4 Desserts:


1) [MRM: HP-10C and up] Starting from no assumptions (angular mode, stack contents, memory contents, etc) write a program to output the constant 9.99999999999 (for 12-digit machines, 12 nines) or 9.999999999 (for 10-digit machines, 10 nines). Your code must be as short as possible. For instance, in the HP-71B you could use:

      1 DISP 9.99999999999

but this is 14 bytes long and as "1 DISP" itself takes 5 bytes you're using 9 additional bytes to generate the constant, which are way too many. I'll give an 8-5 = 3-byte solution for the plain vanilla HP-71B, see what you can do with your favourite HP calc.

      
2) [HP-71B specific; perhaps RPL models too, not sure] Everyone has seen math expressions which give the machine value of Pi as a result so let's try for a slightly different thing here.

Starting from no assumptions (angular mode, stack contents, memory contents, etc) find the shortest, simplest command-line math expression which upon evaluation in your calc produces the machine value of -Pi (i.e.: -3.14159265359 for 12-digit calcs, -3.141592654 for 10-digit ones).

Your expression can't use PI (of course!), strings/string functions, trigonometric/logarithmic/exponential/gamma/complex functions, and also last but not least, neither any digits (in any base) nor "-" should appear in it. I'll give a 6-byte, 16-character solution for the HP-71B, let's see yours.

Also, if you succeed, try to get -Pi/100 or even -Pi/10000 under the same conditions. I'll also give a 6-byte solution for those as well.

      
3) [MRM: HP-11C and up] Informally, for real-valued functions of real-valued arguments we may say that G(X) is the inverse function of F(X) if theoretically G(F(X)) = X. For instance, with F(X)=EXP(X) we have that G(X)=LN(X) and G(F(X)) = LN(EXP(X)) = X.

This said, produce some real-valued F(X) of a real-valued argument X and its theoretical inverse G(X) for your favourite HP calc such that the actual evaluation of G(F(X)) differs from X by at least 2% of X for some relatively small argument X, say X less than 20 in absolue value. No code required, just the F(X) and G(X).

If you succeed in finding such an F(X), try to find the smallest value of X which results in said 2% difference.

I'll give my solution for the HP-11C, HP42S and HP71B (the exact details differ slightly from calc to calc).

      
4) [HP-71B specific; perhaps RPL models too, not sure] Produce the shortest single-statement command-line expression which when executed outputs this line:

      0 1 2 3 4 5 6 7 8 9 10

Your expression can´t use either strings/string functions or any digits in any base and must fit in a single 1-statement line (i.e., no statement concatenation via @ in the HP-71B) less than 80 characters in length, and also can't call any program code, it must generate the ouput by itself.

I'll give my 74-character solution for the HP-71B in a few days but meanwhile give it a try !

Finally, a caveat: PLEASE do NOT include "CODE:" panels in your replies to this thread, as it makes it difficult for me to generate the final PDF document which will include the full thread in order to make it available online for free and for everyone in the future. I sincerely expect you'll kindly comply with this reasonable requirement but in any case I'll remove from the final PDF document any replies featuring CODE: panels. Thank you.

That's all. Hope you'll enjoy it !

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
[VA] Short & Sweet Math Challenge #22: April 1st, 2018 Spring Special - Valentin Albillo - 04-01-2018 09:08 PM



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