Open rdstern opened 2 years ago
Note: The code provided above works correctly in the script window in PR #8551.
@lloyddewit that's great. I have started thinking of the teaching needed and note the importance given to functions. There is another issue I raised elsewhere about perhaps adding a functions keyboard and happy numbers could be there.
That cannot be for this year. But I would still like some interesting functions to go into our script library. I'd like to link to this issue soon, and then we can close it.
I hope to have time, before the main release to tidy the issues.
@lloyddewit perhaps an example for the new script window!?
Happy numbers are fun! They are defined using sums of squares, but in a rather curious way. They are the sums of squares of the digits in each number. So ssqd(13) = 1^2 + 3^2 = 10. Then ssqd(10) = 1^2 + 0^2 = 1. That sequence means 13 is a happy number. If you do the same with 7, you find 7 is also a happy number. (The sequence is 7 > 49 > 97 > 130 - then that's like 13, so it gets to 1 also and is happy).
There is an article called Sums of Squares of Digits by Alan F Beardon. Here it is: The Mathematical Gazette Vol. 82, No. 495 (Nov., 1998), pp. 379-388 (10 pages) Published By: The Mathematical Association.
More generally here he is on happy numbers:
I have proposed adding a key in our calculator for
Happy
numbers. (There is a function in the Zseq package) But understanding them needs the ssq of the digits. That's (of course) another sequence in the Encyclopedia of Integer Sequences. Here:There is also code for producing these ssqd sequences in this reference - but not in R. Here, from the encyclopedia, is the code (apparently) in Python:
So I asked Sam Dumble from Stats4SD for a function in R and here is his response:
He added a function that goes further and (I think) checks whether a number is happy. happy_digits.zip
I wonder (instead) about code - maybe including a function - the get the sum-of-squares of the digits. But then perhaps to go further and produce further columns that continue the sequence. So it would go, perhaps showing: x1 x2 x3 x4 x5 x5 x6 x7 1 1 1 1 1 1 1 1 1 1 2 4 16 37 58 89 145 42 20 4 3 9 81 65 61 37 58 89 145 42 20 4 4 16 etc (The first variable is just the numbers from 1 upwards. The second is the sum of squares of the digits. Then the third should be a simple function from the first and second variables.
The 4th is the same Perhaps we go to about 12 variables? The result is the data frame, which can then be saved or used.
This could be saved as a data-frame and then used in the library. Or the program could be run.
Perhaps this could become an example using the new improved script windows in R-Instat?
We should also (maybe) follow Alan Beardon and write about them! 4 16 37 58 89 145 42 20 4