Post Reply 
[VA] Short & Sweet Math Challenge #25 "San Valentin's Special: Weird Math"
03-04-2021, 02:53 PM (This post was last modified: 03-04-2021 02:59 PM by Gerson W. Barbosa.)
Post: #50
RE: [VA] Short & Sweet Math Challenge #25 "San Valentin's Special: Weird Math...
(03-02-2021 02:55 AM)Valentin Albillo Wrote:  Gerson W. Barbosa, who posted RPL code for such models as the HP50G and BASIC code for the HP-75C, ...
...
Alas, he didn't post any details on his sleuthing, particularly how he managed to find the correct "remarkable and striking numerical property", which would be fascinating for sure but never mind, Well Done !

Hello, Valentín,

Thank you for the compliment and sorry for the belated reply (I’ve been busier than usual lately).

Unlike you, didactics is not one of my strengths, but I will try to demonstrate how I arrived at the solution to your sixth concoction. At first I was not intending to participate in any of these as I was 400 kilometers away from home and I had brought no calculator along. When I visited this thread again, all the other concoctions had been solved. It was late in the evening already, I had neither pencil nor paper but I found a copybook and a pen somewhere and decided to give it a go. As I am not smart enough to look at a small set of numbers and spot its common property right away, I submitted all your examples but one to Wolfram Alpha, which told me that
2020 = 16² + 42² = 24² + 38²;
1348 = 18² + 32²;
1556 = 20² + 34²;
458 = 13² + 17²;
1849 = 43² + 0² and
666 = 15² + 21².
“Quite easy!”, I thought. These are just numbers that can be represented as a sum of two squares (although that didn’t look like a ‘striking’ property to me). Then I wrote a simple RPN program on the emulated 49G+ on my smartphone running m48+:

« { } 0 71
FOR x x 71
FOR y x SQ y SQ + +
NEXT
NEXT SORT DUP SIZE 1 - 1 SWAP
FOR k k GETI UNROT GETI NIP ROT == { k { 0 } REPL } IFT
NEXT SORT
WHILE DUP HEAD NOT
REPEAT TAIL
END
»


After a rather long time, it returned a list with way more elements than the one specified by you (less than 100 elements), even when discarding the ones greater than 5000. Also, one of your examples were missing: 662. It turns out that was the only one I had left out.

I was disappointed of course, but not everything was lost. I noticed that two of your examples involved either the some of the squares of consecutive primes or the square of a prime: 458 and 1849. The Wikipedia article on 666 only confirmed that 666 = 2² + 3² + 5² + 7² + 11² + 13² + 17². Likewise, it wasn’t difficult to verify that all the remaining examples could be expressed as the sum of the squares of consecutive prime numbers. Now, I only needed to figure out a suitable algorithm. But at daft o’clock my reasoning was starting to fail, so I went to sleep and early next morning after I woke up I soon came out with a working program. The argument to the program in post #15 is the number of elements in the list of the squares of the first consecutive prime numbers, { 4, 9, 25, 49, 121, ... }. I started with a 15-element list, but I noticed the resulting list of ‘weird years’ would not include some of your examples. Then I increased it to 16, then to 20, when the list seemed to be complete (the list up to 5000 would not be changed by further increases). I thought it would be nice if the program calculated the size of the basic list automatically, so I researched at OEIS, which led me to an interesting recent article on the subject. That’s where I ‘borrowed’ the formula I used in my next programs, which has to do with the size of the list of the first squares of primes necessary to produce the list of all years up to certain limit (hopefully I have simplified the correct formula – the article looks complicated to me). Next day I was tired after driving all the way back home, but I took the time to write an HP-75C version per your suggestion of using programming languages other than RPL for more clarity. But it payed off, as I noticed the BASIC program was more optimized than the RPL program (the output list never would grow longer than it needed to be). As a result, I was able to write a faster RPL program, but really expert RPL programmers, which I am not, can optimized it even more.

Thank you also for taking the time to concoct these S&SMCs. Even when we don’t participate it’s a joy just to read them, especially your final comments and solutions.

Best regards,

Gerson.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] Short & Sweet Math Challenge #25 "San Valentin's Special: Weird Math... - Gerson W. Barbosa - 03-04-2021 02:53 PM



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