Categories
matematikk

Self numbers and self primes

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 🙂

By hoyd

Communication adviser at Andøya Space.