Message Boards Message Boards

Visualization of happy and sad numbers

Anonymous User
Anonymous User
Posted 9 years ago

I'm trying to visualise the "happy" / "sad" numbers. The process: You take the digits of your starting number, square them and add them up. Now you take this number and do the same thing until you get either 1, which means your starting number is a happy number, or a number in this cycle: 4 - 16 - 37 - 58 - 89 - 145 - 42 - 20 (- 4), and therefore meaning you've started with a sad number.

Do[y = x; 
 y = Total[Power[#, 2] & /@ ToExpression@Characters[ToString@y]]; 
 GraphPlot[{x -> y}], {x, 99}]

This is my current code (how I read it): "y" gets the values of "x", afterwards you sum up the squares of y's digits, and finally you make a connection between the starting number and the number after this one iteration. -- What am I doing wrong?

I moved on as this didn't work, so I've printed the connections and put them into one GraphPlot, which did work. The only problem (I've attached it): it isn't clear and vivid. My idea is to change the size (and maybe colour [right now at most 15 different colours]) of the vertices depending on the number of iteration until it hits 1 or a number in the cycle 4 - 16 - etc. -- Is this possible?

enter image description here

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract

Be respectful. Review our Community Guidelines to understand your role and responsibilities. Community Terms of Use