A bit more often than weekly coding challenge #3 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

A bit more often than weekly coding challenge #3

Look at my comment explaining what happy numbers are. Choose between the following tasks: 1. Have the user enter a number and check if it is happy. 2. Have the user enter a number n and print the first n happy numbers. 3. Have the user enter a number n and print all happy numbers lower than or equal to n. 4. Have the user enter 2 numbers m and n and print all happy numbers between m and n. When you did this, post it on SL and link it here, also tell me if future challenges should be easier or harder.

19th Apr 2017, 4:26 PM
Supersebi3
Supersebi3 - avatar
13 Answers
+ 7
To find out whether a number (positive integer) is happy, replace it with the sum of the squares of its digits. Repeat that process until the number equals 1. If it reaches 1, the starting number is happy. Else it loops in a cycle which does not include 1.
19th Apr 2017, 4:26 PM
Supersebi3
Supersebi3 - avatar
+ 10
@Valdemar @Alvaro nice little codes, both work without flaws, Valdemar's code is my personal favourite between your two because it also shows the steps inbetween, while Alvaro's code is very short and simple, which I appreciate as well If you want, you can also try the other 3 options I put, but you don't have to.
19th Apr 2017, 5:06 PM
Supersebi3
Supersebi3 - avatar
+ 9
@Tobi the print statement looks a bit messy, otherwise its good
20th Apr 2017, 3:21 PM
Supersebi3
Supersebi3 - avatar
+ 8
@Tobi a neat code as well, it looks a bit complicated but thats not important, nice code!
19th Apr 2017, 7:47 PM
Supersebi3
Supersebi3 - avatar
+ 7
@Dodge Cooper no
20th Apr 2017, 1:07 PM
Supersebi3
Supersebi3 - avatar
19th Apr 2017, 5:19 PM
Tob
Tob - avatar
+ 3
I think my solution is pretty pythonic (now that I replaced the map with a generator expression). What would you recommend to simplify the code?
20th Apr 2017, 3:20 PM
Tob
Tob - avatar
+ 3
I have to admit, that's​ a little hacky. :D
20th Apr 2017, 5:30 PM
Tob
Tob - avatar
19th Apr 2017, 4:56 PM
Valdemar
Valdemar - avatar
19th Apr 2017, 4:59 PM
Álvaro
30th May 2017, 1:24 AM
SC Lee
SC Lee - avatar
0
https://code.alviercos.com/clEMiMF5WvkZ
20th Aug 2021, 6:05 PM
hridoy rl
20th Apr 2017, 11:07 AM
Dodge Cooper
Dodge Cooper - avatar