Categories
matematikk

Self numbers and self primes

In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. A number N is said to be a self number if it cannot be written as m + the sum of digits of m for any m.

To find out if a given number is a self number, the idea is to iterate from 1 to N and for each number check that sum of its value and sum of its digits is equal to N or not. If yes then the number is not a self number. Otherwise, the number is a self number.

Okay, I’ve understood self numbers (1, 3, 5, 7, 9, 20, 31, 42, 53,..) and self primes (3, 5, 7, 31, 53, 97, 211,..) now, and can find them using Python.

# !/usr/bin/python3
# Coding: utf-8
import sys
# Function to check if number is prime
def isPrime(n):
return all(n % i for i in range(2, n))
# Function to check for Self number
def isSelfNumber(n):
for m in range(1, n + 1):
if (m + sum(int(digit) for digit in str(m)) == n):
return False
return True
# Check if the number is a self number (and self prime) or not
def main():
try:
n = sys.argv[1]
if (isSelfNumber(int(n))):
if isPrime(int(n)):
print("\nYes,", n, "is a self-number AND a self-prime")
else:
print("\nYes,", n, "is a self-number")
else:
print("\nNo,", n, "is NOT a self-number")
except:
print("\nProvide a number to check")
if __name__ == '__main__':
main()
view raw self-numbers.py hosted with ❤ by GitHub

But a question still remains; is there a practical usage to them or simply the curiosity itself, which I enjoy 🙂 I resolved to Twitter:

The response I got was the there isn’t any known application for them, a part from the curiosity itself 🙂

Try yourself here: jdoodle.com/ia/2RI using the Commandline argument to enter a number to test for self number.

Sources:

By hoyd

Communication adviser at Andøya Space.