
When I first explored Happy Numbers I didn't use a spreadsheet. So what?" But the investigation did lead me to try out an Excel function which looked up results I had already calculated, and that was a worthwhile discovery.Īs always, the main value of the spreadsheet when investigating a mathematical situation, is to give results quickly and easily, so that as much of my attention as possible is available to think about any patterns or connections I notice. When I found answers, my response was "OK, now I know. I should admit that the Happy Numbers investigation itself has That is what happened for me with this investigation.

Sometimes a mathematical situation seems to have no particular purpose but, if our curiosity is excited, and our minds become energised, then exploring a situation's possibilities may reveal an interesting structure or lead us to invent a technique that could be useful elsewhere.

Using a spreadsheet for mapping sequences of this kind The first number in the chain is split into individual digits, each digit is squared and the sum of these squares becomes the next number in the sequence, and so the process continues splitting, squaring and adding.įor example, starting with 35 the next number is 34, that's 9 + 25, the number after 34 is 25, followed by 29, 85 and so on.Įxplore this process for yourself to see what happens.ĭo numbers just get larger and larger, or is there a limit?ĭo numbers eventually map back to themselves? It works like this:Ĭhains of numbers are made. During that period, and with 4 available CPU cores, 1, 018, 708 microseconds ( 1.018708 seconds) were spent in user mode 16, 982 microseconds ( 0.016982 seconds) were spent in system mode 2, 289, 152 bytes of memory allocated.I was first shown Happy Numbers twenty years ago. 5, 372 microseconds ( 0.005372 seconds, 0.52%) of which was spent in GC. ( LENGTH ( FIND-UNDEPRESSED-NUMBERS 1000000)) 3, 320 minor page faults, 0 major page faults, 0 swaps. During that period, and with 4 available CPU cores, 1, 778, 021 microseconds ( 1.778021 seconds) were spent in user mode 140, 862 microseconds ( 0.140862 seconds) were spent in system mode 185, 438, 208 bytes of memory allocated. More performances out of the previous code, just try that solution: Who would have believed that? So if you want to easily get some

It turns out that to solve math related problem, some maths hindsight is To get them one after the other, we’re now

#Happy numbers code
Of course that code is much faster than the one I wrote before both in SQLĪnd Emacs Lisp, the reason being that instead of writing the number into a 1 minor page faults, 0 major page faults, 0 swaps. During that period, and with 4 available CPU cores, 1, 431, 332 microseconds ( 1.431332 seconds) were spent in user mode 145, 941 microseconds ( 0.145941 seconds) were spent in system mode 185, 438, 208 bytes of memory allocated.
