0

Program on kaprekar number.

A number say 45 when squared gives 2025, so 20+25 gives 45. But my program gives me "Time limit exceeded". Can somebody tell me what am i doing wrong. Learning python new. https://code.sololearn.com/c2NTNAnpEFM8/?ref=app

19th Mar 2019, 5:55 PM
Sagnik Majumder2
Sagnik Majumder2 - avatar
10 Respostas
+ 4
The while loop is infinite. The condition n!=0 is always true because n never decreases.
19th Mar 2019, 6:32 PM
Diego
Diego - avatar
+ 2
Nice code Sagnik, where did you get the formula for unique number? the one I found online has different specification here: http://www.guideforschool.com/203266-java-program-to-check-for-unique-number/ And why you check elif n%10 < 0? are you accepting negative numbers?
20th Mar 2019, 5:01 AM
Ipang
+ 2
Sagnik no problem, good job you fix the problem. Can kaprekar number program accept negative input? please explain the elif n%10 < 0 because I don't understand ...
20th Mar 2019, 5:13 AM
Ipang
+ 2
Sagnik Majumder2 Good job! We can simplify it like this ... n1 = count // 2 if count % 2 != 0: n1 += 1 This way we don't need an else block at bottom ... Please edit the forum question, so not confuse people, it still says "Program on unique number." 😁
20th Mar 2019, 6:18 AM
Ipang
+ 2
Sagnik I made a mistake up there in code sample, but now it's fine, I changed it, just letting you know ... 👍
20th Mar 2019, 6:27 AM
Ipang
+ 1
Thankx i have made the required changes😁
20th Mar 2019, 4:34 AM
Sagnik Majumder2
Sagnik Majumder2 - avatar
+ 1
Sry my bad, its kaprekar number. Thanks 😅
20th Mar 2019, 5:09 AM
Sagnik Majumder2
Sagnik Majumder2 - avatar
+ 1
Actually i am using the while loop to find the length of the number, so the if statement counts the number to till the last digit. I have used the elif statement to increase the count by 1 for the last(first) digit.
20th Mar 2019, 5:22 AM
Sagnik Majumder2
Sagnik Majumder2 - avatar
+ 1
It seems my code dont work for numbers like 297
20th Mar 2019, 5:24 AM
Sagnik Majumder2
Sagnik Majumder2 - avatar
+ 1
Yeah i removed that😊
20th Mar 2019, 6:21 AM
Sagnik Majumder2
Sagnik Majumder2 - avatar