... 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.

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 HomageNumber 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 SB(N) which returns the sum of the base-B digits of an integer N. For instance:

Write a program that accepts a base B(2 to 36) and outputs in order those primenumbers N such that SB(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):

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 .

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.: e0) and matter of fact we have that 77.4019.. is the 26th term in the sequence and 231.4859... is the 61th 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 kth 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,000th term and the 3,141,593th term when P = e as well as the 1,234,567th term and the 2,718,282th 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-stepRPN program for the HP-25 (which should work with little or no change in all RPN-based HP calcs).

Write a program that takes no inputs but computes and outputs the limit of the sum of the coefficients a0, a1, ... , an-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 maximumaccuracy (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 !

(I noticed that the SSMC24 was Valentin's post #314 at the time of writing :-)

Tier 5: Guru
In summary : Write a program or function cin(x) which has the defining property that cin(cin(cin(x))) = sin(x).
Once written, use it to tabulate cin(x) for x = 0.0, 0.2, 0.4, ..., 1.0

From the properties of sin we can restrict the search of cin(x) in the interval [0,pi/2].

The problem implicitly assumes that the cin(x) function is unique, otherwise it would make no sense to discuss the cin(x) values.
If we understand 'function' in the mathematic sense of an analytical, non-pathologic function, this may be true.

But if we understand 'function' in the computer science sense of a procedure that takes one argument and returns one result, there are very likely many cin 'functions' such as cin(cin(cin(x)))=sin(x)
One such solution for the HP71 is below:

(03-22-2019 08:04 AM)J-F Garnier Wrote: (I noticed that the SSMC24 was Valentin's post #314 at the time of writing :-)

Yes, that was intentional on my part. Notice also that Paul Dale's post just before yours is his post #1444, i.e. 382, which has the maximum number of 4's (three) in which a square can end.

Quote:The problem implicitly assumes that the cin(x) function is unique, otherwise it would make no sense to discuss the cin(x) values. If we understand 'function' in the mathematic sense of an analytical, non-pathologic function, this may be true.

Yes, that's the kind of "function" I intended.

Quote:But if we understand 'function' in the computer science sense of a procedure that takes one argument and returns one result, there are very likely many cin 'functions' such as cin(cin(cin(x)))=sin(x)
One such solution for the HP71 is below ...

Quite clever of you to find the trick, but certainly that's not what I intended as a solution. The trick will work for any function (not just sin(x) ) and for any number of function compositions (not just 3), but it's of no mathematical value or interest whatsoever.

Also, you overdid it a little, there's no need of EXP's or LN's to make it work, simply adding and later subtracting a suitable constant would do just as well (and faster). Finally, your line

30 IF X=0 THEN Y=0 @ GOTO 70

can be shortened to

30 IF X=0 THEN END

because if a multi-line user-defined function ends without assigning the return value then it simply returns 0 by default. And IF X=0 can be replaced by IF NOT X

Quote:I don't take this solution too seriously :-)

Indeed you shouldn't, neither do I ...

Quote:Still searching for a better one...

Good luck with that, I'm sure you'll succeed and I'm eager to see what you come up with.

Very glad to see you post here, much appreciated. Thanks for your continued interest in my S&SMC's and have a nice weekend.

V.

P.S.: What would it take to lure you into releasing a version of Emu71 which would run on a 32-bit or 64-bit Windows OS, or at least on Android ? Begging ? Bribing ? Taking some relative hostage ? Just plain ol' money ? You tell me, please, it's really affecting my productivity !!

(03-23-2019 12:40 AM)Valentin Albillo Wrote: HiJ-F, long time no see !
...
Very glad to see you post here, much appreciated. Thanks for your continued interest in my S&SMC's and have a nice weekend.

I'm still following your various challenges, even participated to the the last one.
And when I don't participate, it may just mean I have nothing interesting to contribute.

Quote:

Quote:Still searching for a better one...

Good luck with that, I'm sure you'll succeed and I'm eager to see what you come up with.

I investigated a few ideas, without success up to now.

Quote:P.S.: What would it take to lure you into releasing a version of Emu71 which would run on a 32-bit or 64-bit Windows OS, or at least on Android ?

It's a bit OT - well maybe not so much since the HP71 and Emu71 are your favourite tools for your challenges.
In short, the answer is that I don't have the competences to port my Emu71/Dos to Windows, MacOS, Linux, not to mention iOS, Android. However, Emu71/DOS is open source...
And you know for sure that there is already an excellent Emu71 running on Windows (32/64 bits), and also an HP71 emulator for Android.

(03-23-2019 12:40 AM)Valentin Albillo Wrote: P.S.: What would it take to lure you into releasing a version of Emu71 which would run on a 32-bit or 64-bit Windows OS, or at least on Android ? Begging ? Bribing ? Taking some relative hostage ? Just plain ol' money ? You tell me, please, it's really affecting my productivity !!

Valentin - Emu71/DOS runs great on Win7/8/10 (including x64) operating under DOSBOX, though of course not at the full speed it would run if running as native code.

So, if by productivity you mean having to change to a DOS machine to run Emu71, then the above would save a lot of time and hassle, however if raw Emu71 execution speed is the issue, this may not be a big increase in speed, if it increases at all.

As for using Christoph's EMU71/Win, you can remove the "run at actual speed" option and have much higher speed, but I don't know how it compares to native Emu71/DOS on your machine.

If you send me a sample program with relatively long run-time, I'd be happy to time it running on my PC under both Emu71/DOS/DOSBOX and Emu71/Win at it's max speed. This is an older PC with a XEON 3GHz CPU running Win7x64, so not the fastest, but it at least provides some relative performance numbers.

(03-22-2019 08:04 AM)J-F Garnier Wrote: Tier 5: Guru
In summary : Write a program or function cin(x) which has the defining property that cin(cin(cin(x))) = sin(x).
Once written, use it to tabulate cin(x) for x = 0.0, 0.2, 0.4, ..., 1.0
...
Still searching for a better one...

(03-23-2019 04:03 PM)Albert Chan Wrote: cin(x) should be an odd function, shape like sin(x), with value between sin(x) and x

Since cin(x) is an odd function, its Taylor expansion can be written as cin(x)=x+a*x^3+b*x^5+...
So my approach was to build the Taylor expansion of cin(cin(cin(x))) and identify it to the well known sinus expansion sin(x)=x-x^3/3!+x^5/5!...
The x^3 term is easy to calculate and is just -(1/3!)/3=-1/18, in agreement with Albert's approximation (-1/3!+1/9).
The best I could calculate (by hand) was the x^5 term. Then I search for the x^7 term by try-and-error to minimize the error.
Here is my best approximation and results showing cin(cin(cin(x))) and sin(x):

First of all, thanks to all 5 of you who contributed to this thread so far, namely Albert Chan, Paul Dale, J-F Garnier, Oulan and Gerson W. Barbosa, your efforts and interest are much appreciated (and also thanks for not using CODE sections as I requested).

A week has elapsed and now I'll post my original solutions and comments to the different tiers discussed, one at a time, beginning with Tier 1:

Tier 1 - The Challenge:

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. Write a program that takes no inputs but simply finds out and outputs just how many Homage Numbers there are.

My original solution:

This tier was expressly created to be really easy so anyone interested could write code to solve it without much trouble. Matter of fact, as Albert Chan realized, it can be solved by hand with just a little thinking. The key is to realize that 41 and 271 are coprime, so every Homage number should be divisible by both and thus by their product, which is 41 * 271 = 11,111.

Also, being a 10-digit number and having all its digits distinct means that its digits are 0, 1, 2, 3, ... , 9 in some order and thus their sum is 1 + 2 + 3 + ... + 9 = 45, which is divisible by 9 so each Homage number has to be divisible by 9 too. As 9 is coprime to 41 and 271, each Homage number N must be divisible by their product, i.e., by 41 * 271 * 9 = 99,999.

Now let's split N into two 5-digit parts, A, B, like this: N = 100,000*A + B, which must be a multiple of 99,999, so subtracting 99,999*A from it the resulting value: 100,000*A + B - 99,999*A = A + B must be a multiple of 99,999 too and, as both A and B are 5-digit long, i.e., less than 100,000, that multiple must be 99,999 itself. Now, considering their individual digits we have:

Now, there are 5! permutations of the 5 pairs, so 120 permutations in all, but each of the 5 pairs has 2 possible orderings, say (a,u) and (u,a), so 25 = 32 variations for each of the 120 permutations and thus there are 120 * 32 = 3,840potential Homage numbers in all.

However, only 9 out of 10 begin with a non-zero digit (numbers beginning with a 0 aren't 10-digits numbers) and so finally there are 3,840 * 9/10 = 3,456 Homage Numbers.

What if we can't or won't engage on such math reasoning ? Well, that's where our trusty HP calc will take away all the drudgery and work out the solution by itself, doing all the work for us in mere seconds and saving our neurons for better endeavours. In my case, this little 2-liner for the HP-71B (fits in just 1 line too) will scan the whole range at steps of 99,999, increasing the count each time the corresponding number happens to have all its 10 digits different:

Those positive real numbers that are either powers or sums of distinct powers of an arbitrary real number P form an increasing sequence whose first term is 1 (i.e.: P0). Write a program which accepts as input both P and an index k and returns the corresponding kth term in the sequence.

Use your program to find the 1,000,000th term and the 3,141,593th term when P = e as well as the 1,234,567th term and the 2,718,282th term when P = Pi.

My original solutions:

Though the concept used in this challenge will work for powers of any number P >= 2, whether integer or real, I purposefully used a sequence of real numbers which were either powers or sums of distinct powers of e instead of powers of an integer to avoid giving as examples some integer sequences that people would immediately search for in OEIS.

For instance, my preliminary (not posted) examples where based on the integer sequences for P = 3 and P = 61, namely:

1 3 4 9 10 12 13 27 28 30 31 36 37 39 40 81 ...

1 61 62 3721 3722 3782 3783 226981 226982 227042 ...

but I decided to use instead P = e and P = Pi, which generate sequences of reals not present in OEIS. That said, the key fact is that the elements which are either powers or sum of distinct powers of a base Pnaturally map to the elements which are either powers or sum of distinct powers of base 2, which of course are all the integers 1, 2, 3... , i.e. precisely the indexes for the elements in the base-P sequence. Thus we only need to find the base-2 expression for a given index and then interpret that base-2 expression as a number in base P, which we then convert to the usual base 10. For example:

It's worth mentioning that for P = 8 and P = 16 there's an even simpler solution for the HP-71B right from the command line. For instance, to find the 123th element in the sequence of powers or sum of distinct powers of 8, simply execute this from the command line:

>BVAL(BSTR$(123,2),8)

299529

which of course agrees with the 1-liner: FNE(123,8) -> 299529.

Also worth mentioning is the fact that my solution also works for P < 2, even for P = 1, P = 0 and P < 0 but then the resulting sequence is no longer in increasing order as is the case for P >= 2. For instance:

So much for Tier 3, thanks a lot to Paul Dale for his interest in this particular tier and for taking the time to create a nice 24-step solution for the HP-25 as well. In the next days I'll post my solutions for the subsequent tiers.

(03-31-2019 02:51 PM)Juan14 Wrote: For the last challenge.
Let cin(x) = sin(x+A), we have:
sin(sin(sin(x+A)+A)+A) = sin(x) or
sin(sin(x+A)+A)+A = x
For a given value of x, we can solve the last equation for A (A is a function of x).