Post Reply 
[VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
04-24-2019, 05:36 AM
Post: #41
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
(04-23-2019 04:59 PM)Albert Chan Wrote:  sb_find(), version 6. Switched to Python to extend search range.
As expected, Python code is even shorter.

Hi Albert, really interesting (and a little beyond my skills), as usual, but wasn't this one of Valentin's rules? :)

(03-21-2019 02:08 AM)Valentin Albillo Wrote:   
Rules:
[list]
[*]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.: RPNRPL71B BASIC/FORTH, etc).

Have a nice day!

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
04-24-2019, 07:57 PM
Post: #42
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
 
Hi, Bernd Grubert, Gilles and Massimo Gnerucci:

(04-20-2019 10:47 AM)Bernd Grubert Wrote:  Here is my solution to Tier 2. It is 192 bytes long, due to the lack of prime number checking and the remainder function on the HP-15C. [...] I have done the test runs on the HP-15C emulator on a PC, since the processing time on my DM-15L is far too long... Since the largest integer number the HP-15C can exactly represent is 9,999,999,999. , this implementation of the Miller-Rabin algorithm can check only number up to 99,999. Due to memory limitations, on the real HP-15C and the DM 15L the longest sequence is 26 values. [...] For base 31 I got the sequence: 619, 18257, ...,(I stopped at 34139 after ~90 min., because I didn't want to wait any longer) [...] For base 7 I got the sequence: 4801, ...,(I stopped at 23451 after ~60 min.) [...] I have attached an HTML-documentation and a txt-file, that can be read into the emulator after changing the extension back to ".15c"

Thanks a lot for your interest and for your nice solution, Bernd, much appreciated !

Matter of fact, I do appreciate your solution over any purported "solutions" written in non-HP calc languages/environments, such as Mathematica, Lua and Python, which I expressly said in my OP that should not be used at all but that certain individual who routinely disregards the rules did nevertheless use, as I discuss below.

You, on the other hand, did abide by the rules and took the trouble to use an actual HP calculator (or emulator) and wote actual RPN code, fearlessly wrestling with its limitations, to produce an actual solution to the challenge I posted, instead of going the lazy route of using high-level languages on a full-fledged PC, which lacks any merit whatsoever and which for me amounts to trolling.

So, again, Bernd, thank you very much for your valuable contribution, my challenges are created for people like you who work hard on them to produce solutions under the constraints given, thus fulfilling my stated purpose, which is to have people using their HP calculators, with their limitations and warts and all, not using some fancy non-HP languages and/or environments, which completely defeats the purpose.


(04-21-2019 07:06 AM)Gilles Wrote:  Tier 1: Here is my solution without reading others responses. I image that there exists better way. This one is "bestial" ;D Always impressed how fast NewRPL is. Brutal force :

1/ HP50g NewRPL or RPL [...] Solved in only 1.3s in newRPL (on my PC) , 116s with HP50g hdw, much much slower in 779s in RPL (on my PC with Emu48). NewRPL 600 times faster in this case on a PC. [...] 2/ HP50g RPL with ListExt, shorter but slower [...]

Thanks a lot for your RPL/NewRPL solutions, Gilles, much appreciated. What I told Bernd above also applies equally to you so for the sake of brevity I won't repeat it here.

Again, thanks for your interest and for your time, hope you enjoyed the challenge as I certainly enjoyed your solutions, keep them coming for future ones !


(04-24-2019 05:36 AM)Massimo Gnerucci Wrote:  
(04-23-2019 04:59 PM)Albert Chan Wrote:  Switched to Python to extend search range. As expected, Python code is even shorter.

Hi Albert, really interesting (and a little beyond my skills), as usual, but wasn't this one of Valentin's rules?

(03-21-2019 02:08 AM)Valentin Albillo Wrote:  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.: RPNRPL71B BASIC/FORTH, etc).

Thanks for pointing this out, Massimo, I didn't read Mr. Chan's posts because I've placed him in my Ignore list so that I don't read his post anymore, as he has shown an utter disregard for the rules I so clearly state in my challenges, thus completely defeating the purpose and probably ruining them for others, which I find profoundly disrespectful.

To wit:
  • The purpose of my challenges is to offer HP-fan fellow readers the opportunity to actually get to use their HP calculators and their languages to solve allegedly interesting math topics, so that perhaps we all learn some new exciting math facts and some worthwhile HP-calc programming techniques which are cleverly used to overcome the natural limitations of our beloved HP calcs and their languages. Nothing more and nothing else.

If some disrespectful individual like Mr. Chan then goes on and completely ignores the requirement to use HP calcs and their languages (RPN, RPL, 71BASIC, 71FORTH, PPL, Saturn assembler, etc) and uses instead exclusively such software as Mathematica, Lua, Python or whatever on a PC to effortlessly overcome the aforementioned natural limitations of our calcs and provide almost-instant solutions, then:
  • No HP calcs/languages are used at all, which completely defeats the intended purpose.
     
  • No HP calcs/languages limitations are overcome at all, with was the idea, as the challenges' difficulty is geared to HP calc/languages, not to Mathematica/Lua/Python running on a PC where the difficulty and inconvenience are diminished by orders of magnitude, which amounts to shameful cheating.
     
  • No HP calcs/languages' new interesting programming techniques are created for everyone to learn, which again completely defeats the intended purpose.

So, what this individual, Mr. Chan, is continuously doing amounts to:
  • Utter disrespect to the rules I explicitly stated, which aren't arbitrary but do have the explicit intended purposes stated above.
     
  • Shameful cheating, as he is using software/harware orders of magnitude more powerful that the intended one, namely HP calcs/languages.
     
  • Spoiling, as he gives lots of versions and explicit solutions with no "spoilers" warnings whatsoever, thus spoiling the fun for any rule-abiding forum readers, and probably discouraging them from even attempting the challenge using their HP calculators.
     
  • Trolling, as he has done this any number of times by now. He did that with my cin(x) challenge, for example, and with all the recent ones. He does it all the time though he could certainly go on and post his Mathematica/Lua/Python code in Mathematica/Lua/Python forums (as he did with my Cin(x) challenge; but he nevertheless posted his Lua or Python code here as well).

In one of my challenges he said something to the effect that he only has an HP-12C at hand but that is hardly a valid excuse as he's obviously using a PC or other device to run his Mathematica/Lua/Python code and there are any number of free emulators of HP calcs available for Windows, Mac, Android and iOS, such as Free42, V41, Emu71/DOS, Emu71/Win, HP-25, most RPL models, Prime, etc. etc., which he could easily use but he doesn't.

This being so, I've placed Mr. Chan in my Ignore list and won't read or comment on his solutions. I'm totally fed up with his continued cheating, trolling and disrespect.

If he's so keen on showing off his abilities he should go and post his Lua marvels in the Lua forums and his Python achievements in the Python forums, not in my challenge threads, or at the very least be an sportman and provide first an acceptable solution using HP calcs/languages, as per the rules. At any rate, if he goes on trolling my challenges here like that, I'll certainly take appropriate measures.

Best regards to all.
V.
 
Find all posts by this user
Quote this message in a reply
04-24-2019, 08:30 PM (This post was last modified: 05-13-2019 06:32 PM by Albert Chan.)
Post: #43
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
Hi, Valentin Albillo

I did not know people were offended.
I had deleted all posts since your last posting.

Sorry about that ...

I did explain my HP-12C can't handle primes.
I am learning the emulation software, but that take some time ...
Tried FPRIM(n) in emu71, but only gives "Err: Invalid Expr"

This is from your last PM to me:

Valentin Albillo Wrote:Hi, Albert Chan:

Your second attempt at Tier 2 is essentially correct but for a minor detail. You posted (for base 7):

lua> sb_find(7)
7     1 <<<<<<<<<<<<<<<
4801     25
201683     35
16470859     49
115296019     55

but your first result above (7 1) is incorrect because 1 is neither a prime nor a composite, it's a unit. Not being a composite, as asked, makes it an invalid result which perhaps you might want to correct in your post before I post my solutions.

Thanks for your interest and your clear & concise solutions, best regards.
V.
.

Update:
Replaced all my Python code with XCas, so HP Prime user can try out.
The 1 Mathematica post and Lua code got quoted by others, so I felt better leave it alone.
At the time, I was too excited when cin puzzle is solved in my head ...
Find all posts by this user
Quote this message in a reply
04-26-2019, 06:13 PM (This post was last modified: 04-27-2019 12:25 AM by Albert Chan.)
Post: #44
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
I did downloaded the Emu71/Windows, but unable to get the code fully worked out.

HP-71B BASIC code below only print out possible sb candidates.
The program cannot be completed without ISPRIME(), so I never posted it.

What it does is output values of permutations of base-B digits that have the inputed sb value.

Quote:10 INPUT "BASE ?"; B
20 INPUT "DIGITS ?"; N
30 DIM S(N),L(N),H(N)
40 INPUT "SB VALUE ?"; S(N)
50 I = N
60 GOSUB 100
70 END

100 L(I) = S(I)-(B-1)*(I-1)
110 IF L(I) < 0 THEN L(I) = 0
120 H(I) = S(I)
130 IF H(I) >= B THEN H(I) = B-1

150 IF L(I) > H(I) THEN RETURN
160 IF I = 1 THEN GOTO 200
170 S(I-1) = S(I)-L(I)
180 I = I-1 @ GOSUB 100 @ I = I+1
190 L(I) = L(I)+1 @ GOTO 150

200 T = 0
210 FOR K = N TO 1 STEP -1
220 T = T*B+L(K)
230 NEXT K
240 PRINT T;

250 INPUT "MORE?";Y
260 IF Y<>0 THEN RETURN

Example: for base-7, upto 12 decimal digits => 15 base-7 digits

>RUN
>BASE ? 7
>DIGITS ? 15
>SB VALUE ? 65

1694851493 → 1936973135 → 1971561941 (first prime)

>RUN
>BASE ? 7
>DIGITS ? 15
>SB VALUE ? 77

83047723205 → 94911683663 → 96606535157 → 96848656799 (first prime)

BTW, where to get ISPRIME() (or equivalent) for the HP-71B emulator ?

Edit: change PRINT "X?" @ INPUT X to INPUT "X?";X
Find all posts by this user
Quote this message in a reply
04-26-2019, 09:50 PM (This post was last modified: 04-26-2019 09:53 PM by rprosperi.)
Post: #45
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
(04-26-2019 06:13 PM)Albert Chan Wrote:  I did downloaded the Emu71/Windows, but unable to get the code fully worked out.

BTW, where to get ISPRIME() (or equivalent) for the HP-71B emulator ?

Congratulations Albert, on upgrading to EMU71! I think you will find much more participation by others with your posts if they include HP code. You happen to have made a good choice as the 71B is my favorite machine, so I can answer many questions about using it, but I can't contribute much regarding a lot of the math you frequently post.

For ISPRIME(), I don't have a LEX file with this, however the PRIMLEX LEX file (PRIM(X) returns the lowest Prime factor of X) found on this page may meet the need.

Also, to input N with a prompt, use this:

100 INPUT "What is N?"; N

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
04-26-2019, 11:36 PM (This post was last modified: 04-26-2019 11:45 PM by Gilles.)
Post: #46
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
(03-28-2019 12:38 AM)Valentin Albillo Wrote:  Tier 1 - The Challenge:
(...)

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.
 

Good catch the divisibility by 9. I totaly missed this.
Find all posts by this user
Quote this message in a reply
04-28-2019, 11:08 AM (This post was last modified: 07-23-2019 01:10 PM by Albert Chan.)
Post: #47
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
Hi, rprosperi

Thanks for the tip. I finally get FPRIM working, but had to switched to EMU71/DOS
This is my updated HP71B BASIC listing.

Quote:10 ON ERROR GOTO 190
20 INPUT "BASE?";B
30 N=CEIL(12/LOG10(B)) @ DIM S(N),L(N),H(N)
40 FOR C=4 TO (B-1)*N
50 IF GCD(C,B-1)=1 AND FPRIM(C,C)=0 THEN
60 T=0 @ I=N @ S(I)=C @ GOSUB 100 @ PRINT C;T
70 END IF
80 NEXT C
90 END

100 L(I)=MAX(S(I)-(B-1)*(I-1), 0)
110 H(I)=MIN(S(I), B-1)
120 IF L(I)>H(I) OR T THEN RETURN
130 IF I=1 THEN GOTO 170
140 S(I-1)=S(I)-L(I)
150 I=I-1 @ GOSUB 100 @ I=I+1
160 L(I)=L(I)+1 @ GOTO 120

170 FOR K=N TO 1 STEP -1 @ T=T*B+L(K) @ NEXT K
180 T=FPRIM(T,T) @ RETURN
190 T=-T @ RETURN

>RUN
BASE? 7
25 4801
35 201683
49 16470859
55 115296019
65 1971561941
77 96848656799
85 -1.3564461457E12

>RUN
BASE? 31
49 619
77 18257
91 59581
119 1787459
121 2769601
133 13851853
143 22164503
161 372178931
169 629810569
187 7987533097
203 23073248663
209 54109095389
217 247613526037
221 357635354291
247 -6.82312829953E12
253 -1.19404745241E13
259 -1.70578207488E13


Ignore lines with negative numbers. It just meant T (for the sb value) overflow 12 digits.

Note: It is possible primes not in sorted order. Example:
>RUN
BASE? 2
4 23
6 311
8 383
...
36 206141652991
38 -1.01361228185E12 <- actual T = 1030791102463
39 824633720831
40 -1.09951162777E12 <- actual T = 2196875771903
Find all posts by this user
Quote this message in a reply
Post Reply 




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