DEV Community

Cover image for I Built a Python Library That Classifies 3000+ Number Types — At 15
Aratrik Ghosh
Aratrik Ghosh

Posted on

I Built a Python Library That Classifies 3000+ Number Types — At 15

I'm 15, in Class 10, and I just shipped my first Python package to PyPI. Here's what I built and why nobody else had done it.

The Problem

There are tons of Python libraries for number computation — factoring, GCDs, prime generation. But none of them answer this:

What type of number is this?

Not just "is it prime?" — I mean every named mathematical category it belongs to.

import numclassify as nc

nc.get_true_properties(1729)
# ['taxicab', 'carmichael', 'zeisel', 'odd', 'deficient', 'squarefree']
Enter fullscreen mode Exit fullscreen mode

1729 is the Hardy-Ramanujan number — smallest expressible as sum of two cubes in two different ways. It's also a Carmichael number and a Zeisel number. Most people only know one of those facts. numclassify knows all of them instantly.

What It Does

3000+ named number types, 10 categories, zero dependencies, Python 3.8–3.13.

Category Count Examples
Polygonal 998 Triangular, Square, Pentagonal…
Centered Polygonal 998 Centered Triangular, Centered Hexagonal…
Prime families 41 Twin, Mersenne, Sophie Germain…
Digital invariants 10 Armstrong, Harshad, Happy, Disarium…
Divisor-based 27 Perfect, Abundant, Weird, Amicable…
Sequences 15 Fibonacci, Lucas, Catalan, Bell…
Powers 13 Perfect Square, Taxicab…
Number theory 14 Evil, Carmichael, Keith…

Quick Examples

import numclassify as nc

# Boolean checks
nc.is_prime(17)         # True
nc.is_armstrong(153)    # True
nc.is_perfect(28)       # True

# All true properties
nc.get_true_properties(153)
# ['armstrong', 'harshad', 'triangular', 'abundant']

# Search a range
nc.find_in_range(nc.is_armstrong, 1, 10000)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474]

# What's the most "special" number between 1 and 1000?
nc.most_special_in_range(1, 1000)
Enter fullscreen mode Exit fullscreen mode

CLI

$ numclassify check 1729
taxicab        ✓
carmichael     ✓
zeisel         ✓
odd            ✓

$ numclassify find armstrong --limit 5
1, 2, 3, 153, 370

$ numclassify info armstrong
Name:        armstrong
Category:    digital_invariants
Description: Sum of digits each raised to power of digit count
Examples:    1, 2, 3, 153, 370, 371, 407
Enter fullscreen mode Exit fullscreen mode

Install

pip install numclassify
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/aratrikghosh2011-tech/numclassify
PyPI: https://pypi.org/project/numclassify/


Built this because I was studying number theory for competitive maths and kept writing the same classification checks over and over. Figured if I needed it, others did too.

Feedback welcome — especially if you find a number type I'm missing.

Top comments (0)