+ 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.
13 Respuestas
+ 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.
+ 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.
+ 9
@Tobi the print statement looks a bit messy, otherwise its good
+ 8
@Tobi a neat code as well, it looks a bit complicated but thats not important, nice code!
+ 7
@Dodge Cooper no
+ 4
My little code:
https://code.sololearn.com/cVMrQsgEKKV4/?ref=app
+ 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?
+ 3
I have to admit, that's a little hacky. :D
+ 2
Pretty fun ☺️
https://code.sololearn.com/ct5fW4Mv4Fwv/?ref=app
+ 2
A quick approach:
https://code.sololearn.com/c44O5aztqO8Q/?ref=app
+ 1
Happy Number in Ruby:
https://code.sololearn.com/clEMiMF5WvkZ
0
https://code.alviercos.com/clEMiMF5WvkZ