# Difference between revisions of "ZCubes/Happy Numbers"

(→Video) |
|||

Line 9: | Line 9: | ||

==Video== | ==Video== | ||

<br/> | <br/> | ||

− | {{#ev:youtube|c1nHGP63Mqo|480|left| | + | {{#ev:youtube|c1nHGP63Mqo|480|left|Happy Numbers}} |

− | <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> | + | |

+ | <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> | ||

+ | |||

+ | ==ZCubes Code== | ||

+ | <pre> | ||

+ | |||

+ | function dohappy(n) | ||

+ | { | ||

+ | prev={} | ||

+ | prevnums=[] | ||

+ | originaln=n | ||

+ | do | ||

+ | { | ||

+ | if(prev[n]) | ||

+ | { | ||

+ | console.log("MELCOIL",originaln,prevnums.concat(n)) | ||

+ | return("MELCOIL") | ||

+ | } | ||

+ | prev[n]=true; | ||

+ | prevnums.push(n) | ||

+ | d=DIGITS(n) | ||

+ | n=SUM(d.$(x=>POWER(x,2))) | ||

+ | }while(prev[n]||n>1) | ||

+ | console.log("HAPPY",originaln,prevnums.concat(n)) | ||

+ | return("HAPPY") | ||

+ | } | ||

+ | dohappy#; | ||

+ | dohappy(2..100) | ||

+ | |||

+ | </pre> | ||

+ | |||

+ | Output:- | ||

+ | |||

+ | 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193 are Happy numbers in the range of 2 to 100. | ||

+ | |||

<br/> | <br/> | ||

*[[Z3 | Z3 home]] | *[[Z3 | Z3 home]] |

## Latest revision as of 04:05, 17 September 2021

## Happy Numbers

This video demonstrates how to generate Happy Numbers. Happy Numbers are numbers of which the sum of squares of digits is computed and then this process is repeated with the computed numbers also until we obtain the result as 1. In some cases 1 is not obtained, so those are termed sad numbers.

Using ZCubes, you can provide a large range of numbers to compute which are the happy numbers in that set. Enjoy watching. Click Subscribe to know more of such interesting numbers.

ZCubes is an omnifunctional platform using which you can compute, do analytics, create graphs, draw, paint, create presentations, web pages and do much more.

## Video

## ZCubes Code

function dohappy(n) { prev={} prevnums=[] originaln=n do { if(prev[n]) { console.log("MELCOIL",originaln,prevnums.concat(n)) return("MELCOIL") } prev[n]=true; prevnums.push(n) d=DIGITS(n) n=SUM(d.$(x=>POWER(x,2))) }while(prev[n]||n>1) console.log("HAPPY",originaln,prevnums.concat(n)) return("HAPPY") } dohappy#; dohappy(2..100)

Output:-

7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193 are Happy numbers in the range of 2 to 100.

© Copyright 1996-2021, ZCubes, Inc.