1

I am writing a program that looks for keith numbers in different bases. Is there a way to iterate through numbers in a certain base? I have a program that can convert decimal to any base, but I'm not sure how to proceed.

This is my code so far.

def is_keith_number(n,base):
   # Find sum of digits by first getting an array of all digits then adding them
   c = str(n)
   a = list(map(int, c))
   b = sum(a)

   # Now check if the number is a keith number

   while b < n:
      a = a[1:] + [b]
      b = sum(a)

   return (b == n) & (len(c) > 1)

I also have a function,

convert()

which converts a number from one base to another. Its unneccesary to show that code, but it does work. Any help?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.