CHALLENGE: HAPPY NUMBERS!!!!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

CHALLENGE: HAPPY NUMBERS!!!!!

Start with any positive integer, replace the number by the sum of the squares of its digits in base-ten, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle that include number 4. Those numbers for which this process ends in 1 are called happy numbers, others are unhappy or sad numbers. Examples: 208 -> 2*2 + 8*8 = 68 -> 6*6 + 8*8 = 100 -> 1*1 = 1 ---> HAPPY NUMBER :) 145 -> 1*1 + 4*4 + 5*5 = 42 -> 4*4 + 2*2 = 20 -> 2*2 = 4 ---> SAD NUMBER :( Write a program that gets a number and says if it is happy or not.

26th Sep 2017, 11:54 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
7 Answers
27th Sep 2017, 3:42 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 20
https://code.sololearn.com/cQrj6XdvguyT/?ref=app
28th Feb 2018, 3:50 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 7
Here's my C# implementation! ✌ No LINQ this time and I gave credit to Amrit in the code since he's the one that propose the same challenge before this. Enjoy~ ❤ https://code.sololearn.com/cbB504rypHIG/?ref=app
27th Sep 2017, 6:20 AM
Zephyr Koo
Zephyr Koo - avatar
+ 4
https://www.sololearn.com/discuss/583252/?ref=app Posted earlier by me...
27th Sep 2017, 12:59 AM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 3
I think this challenge is around plus I had not resolved yet so here my practice on pythonhttps://code.sololearn.com/cymJJVP2fNp8/#py
27th Sep 2017, 1:06 AM
ysraelcon
ysraelcon - avatar
0
My java solution based on easy method and loops https://code.sololearn.com/cg1LLvk0hJN5/#java
24th Apr 2018, 7:37 AM
christine
christine - avatar
0
Very nice & knowledgeable post all features are defined in a good way for more detail visit https://bit.ly/2WapnD4 thanks
18th Jul 2020, 7:31 AM
TreenFetch