+ 16

😁😀Challenge: Happy numbers! 😀😁

A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy (or sad) numbers. A happy prime is a number that is both happy and prime. Find both happy numbers and happy prim

14th Sep 2017, 3:58 AM
noobcøder
noobcøder - avatar
11 ответов
+ 15
My Code: Using Pythonhttps://code.sololearn.com/cSbKDxaUE1SZ/?ref=app The best thing about it (objectively talking) is the proper handling of the endless loop for the unhappy numbers (No Limit Error) However, I didn't test it that much, so in case of an error or bug please tell me ^^ Hope u Like it ♡
11th Aug 2017, 12:23 AM
MizoPro
MizoPro - avatar
+ 8
this code checks whether a number is happy / happy-prime or not........ https://code.sololearn.com/cBcZ6p93elpm/?ref=app
14th Sep 2017, 7:15 AM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
14th Sep 2017, 7:23 PM
LukArToDo
LukArToDo - avatar
+ 7
Here you go. Very little code. Edit: Now prints both happy numbers and happy primes, thanks Noob. https://code.sololearn.com/c8X21fFizgW3/?ref=app
18th Aug 2017, 11:06 AM
Vari93
Vari93 - avatar
+ 4
12th Aug 2017, 9:05 PM
Abdelfattah Toulaoui
Abdelfattah Toulaoui - avatar
15th Sep 2017, 6:11 AM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 2
My code using java: https://code.sololearn.com/cz59ShKT9tIZ If there any bugs or else please tell me. Hope you like it. :)
15th Sep 2017, 2:12 PM
Fabi
Fabi - avatar
+ 2
one day unhappy numbers are going to group up and kill all happy numbers. https://code.sololearn.com/cYZX3Z6H8RH4/?ref=app
16th Sep 2017, 7:03 AM
Jin
Jin - avatar
+ 1
@vari93 it lacks the happy numbers (non primes) though..
18th Aug 2017, 11:37 AM
noobcøder
noobcøder - avatar
0
@Noob Oh lol, I totally spaced on that, just a sec
18th Aug 2017, 11:59 AM
Vari93
Vari93 - avatar
14th Sep 2017, 4:42 PM
Bajrang Kumar
Bajrang Kumar - avatar