Narcissistic Numbers in Python

a sourceforge.net project

Free software to find narcissistic numbers.

Specifically, finds numbers the sum of whose digits raised to the same power equals the number.

Written in Python, licensed under LGPL. Current release is 1.1.

Sample output

$ DigitTest.py 10 9 9
Using b=10, k=9, n=9
Solution range [100000000, 999999999] (decimal)
Iterating over 48620 permutations
Found narcissistic number 534494836 (decimal 534494836)
Found narcissistic number 472335975 (decimal 472335975)
Found narcissistic number 912985153 (decimal 912985153)
Found narcissistic number 146511208 (decimal 146511208)
Encountered:
    permutations (low, in range, high): (9228, 32697, 6695)
    narcissistic numbers found: 4
        534494836
        472335975
        912985153
        146511208

Explanation

In the example above, the number 534494836 is:

Resume after interruption

Narpy has the ability to resume should the current run be interrupted. Do this by running the DigitTest.py script with a filename at the end such as:

$ DigitTest.py 4 4 4 filename

Should you interrupt or kill the process, resume by simply providing the filename:

$ DigitTest.py filename

And it will continue running where it left off. If it is already finished, it reports the final summary of numbers found. That way, you can run it in the background and preserve the results. Then when the background job finishes, run it in the foreground against the filename to see the results of the job.

If you omit the filename, it runs without persistence. With the filename it stores information to the file every time it reports how many permutations are left.

References

Wikipedia: http://en.wikipedia.org/wiki/Narcissistic_numbers

On-Line Encyclopedia of Integer Sequences: http://www.research.att.com/~njas/sequences/A005188