03-21-2019, 02:08 AM

Hi, all ! Happy Spring to all of you !

... and once again to commemorate its arrival, here you are, a brand new Short & Sweet Math Challenge #24 "Spring Special 5-tier" to give you all a chance to put to good use both your favourite HP calculator and your programming ingenuity (*NOT* your Google Search proficiency). Try all 5 tiers below and see what's your top one !

Rules:

- Any HP calc of your choice may be used but I'll suggest a Minimum Recommended Model (MRM) for each tier, which is the simplest model I deem capable of solving it more or less comfortably.

- Using anything other than a physical or emulated HP calculator is strictly disallowed. Also no VBA, Excel. Pascal, C/C#/C++, Java, Python, Haskell, etc. code, please go elsewhere for that. You must write your code in a language supported in some HP calc (i.e.: RPN, RPL, 71B BASIC/FORTH, etc).

- Googling the solutions is lame beyond belief and, frankly, if you do you'll be but a sore loser in my eyes .

Tier 1: Noob

[MRM: HP-11C and up]

Let's begin with something affordable. As it happens, I have 2 HP-71B and a 41C in my collection and I love them dearly so I'll pay them a little homage here: we'll call Homage Number to any 10-digit positive integers which are multiples of 271, divisible by 41 and further their digits are all distinct.

The Challenge:

Write a program that takes no inputs but simply finds out and outputs just how many Homage Numbers there are. No need to output any of them, just count'em and do it fast !

Your code should be as fast and short as possible, in that order. I'll post my original code (a 2-liner) and results for the HP-71B .

Tier 2: Beginner

[MRM: HP-29C and up]

Consider the function S

_{B}(N) which returns the sum of the base-B digits of an integer N. For instance:

S

_{2}(2019) = S

_{2}(11111100011

_{2}) = 1+1+1+1+1+1+0+0+0+1+1 = 8

S

_{5}(2019) = S

_{5}(31034

_{5}) = 3+1+0+3+4 = 11

S

_{10}(2019) = 2+0+1+9 = 12

S

_{16}(2019) = S

_{16}(7E3

_{16}) = 7+E (=14) +3 = 24

S

_{36}(2019) = S

_{5}(1K3

_{36}) = 1+K (=20) +3 = 24

The Challenge:

Write a program that accepts a base B (2 to 36) and outputs in order those prime numbers N such that S

_{B}(N) is composite and distinct from the previous ones.

For instance, this is what your program should generate for bases B = 6, 8 and 16 (hexadecimal):

B = 6: 11, 19, 23, ... 179, ...

B = 8: 11, 13, 23, ... 191, ...

B = 16: 19, 23, 29, ... 223, ...

Once verified that your code reproduces the above sample results, go on and generate the corresponding sequences for base B = 31 first and then for base B = 7 .

What results do you get ? Which is the smallest (first) prime in each sequence ? How many elements can you generate for each sequence ? What about other bases ?

Again, your code should be as fast and short as possible, in that order. I'll post my original code (a 6-liner) and results for the HP-71B .

Tier 3: Intermediate

[MRM: HP-25 and up]

Consider the real numbers 77.4019... and 231.4859... , which are sums of distinct non-negative integer powers of e (= exp(1) = 2.71828...):

77.4019... = e

^{1}+ e

^{3}+ e

^{4}

231.4859... = e

^{0}+ e

^{2}+ e

^{3}+ e

^{4}+ e

^{5}.

Those positive real numbers that are either powers of e or sums of distinct powers of e form an increasing sequence whose first term is 1 (i.e.: e

^{0}) and matter of fact we have that 77.4019.. is the 26

^{th}term in the sequence and 231.4859... is the 61

^{th}term.

The Challenge:

Generalizing to powers of an arbitrary real number P >= e, write a program or function which accepts as input both P and an index k and returns the corresponding k

^{th}term in the sequence (in the example above we would have MyFunction(e, 26) = 77.4019... and MyFunction(e, 61) = 231.4859... ). Your code should be as short and fast as possible.

Now use your program/function to find the 1,000,000

^{th}term and the 3,141,593

^{th}term when P = e as well as the 1,234,567

^{th}term and the 2,718,282

^{th}term when P = Pi. Also, just for show, use it to list the first 10 terms or so for each sequence.

I'll post both a 1-line user-defined function for the HP-71B and an equivalent 24-step RPN program for the HP-25 (which should work with little or no change in all RPN-based HP calcs).

Tier 4: Advanced

[MRM: HP-11C and up]

Consider the n-point dataset (x

_{i}, y

_{i}) where x

_{i}= 1, 2, 3, 4, 5, 6, ..., n (the natural numbers) and y

_{i}= 2, 3, 5, 7, 11, 13, ..., p

_{n}(the prime numbers), and the (n-1)

^{st}degree polinomial fit to this dataset of the form:

P(x) = a

_{0}+ a

_{1}(x-1) + a

_{2}(x-1) (x-2) + ... + a

_{n-1}(x-1) (x-2) (x-3) ... (x-(n-1))

The Challenge:

Write a program that takes no inputs but computes and outputs the limit of the sum of the coefficients a

_{0}, a

_{1}, ... , a

_{n-1}when n tends to infinity. Your program must be as short and fast as possible and must compute the limit to the 10-12 digits maximum accuracy of your calc, give or take a few ulps.

I'll post a 4-line, 168-byte program for the HP-71B which computes and outputs the limit in ~0.2 sec (Emu71) but a fast RPN version for the HP-11C and up is also perfectly possible.

Tier 5: Guru

[MRM: HP-11C and up]

Surely you're well aware of the elementary trigonometric function sin(x), you know, the wavy one. Now consider a related function, which henceforth I'll call cin(x) which has the defining property that cin(cin(cin(x))) = sin(x).

The Challenge:

Write a program or function which accepts an argument x in the range [-Pi, Pi] and outputs the corresponding value of cin(x). The faster and shorter the better but you should strive for maximum accuracy (at least 8-10 correct digits in the whole range, give or take a few ulps).

Once written, use it to tabulate cin(x) for x = 0.0, 0.2, 0.4, ..., 1.0 and also to compute cin(Pi/2), cin(-0.71), cin(2.019), and with the experience gained do likewise with another similar function tin(x) which has the property that tin(tin(x)) = sin(x).

I'll give a short program for the HP-71B which achieves about 10 correct digits for any argument in [-Pi, Pi].

Hint: You can check that you get adequately accurate values of cin(x) by simply computing cin(cin(cin(x))) and comparing the results with sin(x). Likewise with tin(x).

Finally, the usual caveat:

- Please do NOT include CODE panels in your replies to this thread, as it makes it difficult for me to generate the online PDF document which will include the whole thread. I expect you'll kindly comply with this requirement but otherwise I'll remove from the final PDF document any replies featuring CODE panels. Thank you.

I'll post my original solutions in a week or so but meanwhile let's see what you can do.

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

V.