You are viewing a single comment's thread. Return to all comments →
Python 3 1-liner
def kaprekarNumbers(p, q): if not [print(n, end=" ") for n in range(p, q + 1) if (int(str(n*n)[:-len(str(n))] or 0) + int(str(n*n)[-len(str(n)):])) == n]: print("INVALID RANGE")
Almost same code but unraveled
def kaprekarNumbers(p, q): found = False for n in range(p, q + 1): num = str(n*n) l = num[:-len(str(n))] r = num[-len(str(n)):] if int(l or 0) + int(r) == n: found = True print(n, end=" ") if not found: print("INVALID RANGE") return
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
Python 3 1-liner
Almost same code but unraveled