Hackerrank Modified Kaprekar Numbers Solution


hacker rank Kaprekar Numbers

This is the solution to the Modified Kaprekar Numbers found in the implementation section of the algorithm domain in Hackerrank. A modified Kaprekar number is a positive whole number n with d digits, such that when we split its square into two pieces – a right hand piece r with d digits and a left hand piece l that contains the remaining d or d−1 digits, the sum of the pieces is equal to the original number (i.e. l + r = n).





The Code
def sendKap(x, s):
  y = x * x
y = str(y)
s1 = y[: len(y) / 2: ]
s2 = y[len(y) / 2::]
s3 = int(s1) + int(s2)
if (s3 == x):
st = input()
en = input()
s = []
for i in range(st, en + 1):
  if (i & gt; 9):
    sendKap(i, s)
elif(i == 1):
elif(i == 9):
if (len(s) == 0):
else :
  print ' '.join(s) < /pre>

Got any problems feel free to comment them here!

Related posts

Leave a Comment