Recreational Maths in Python - Alan Zucconi
pythonrecreational-mathematicsnumerical-sequencesparallel-computing
Abstraction: Python techniques for computing narcissistic, Kaprekar, and happy number sequences
Key points:
- Python's arbitrary-precision integers (auto-cast from int to long) make it ideal for digit-manipulation sequences without external libraries
- Narcissistic numbers: an n-digit number equal to sum of its digits each raised to power n; e.g. 153 = 1^3 + 5^3 + 3^3
- Kaprekar numbers: square the number, split digits, left part + right part equals the original; requires careful digit-split logic
- Happy numbers converge to 1 under repeated sum-of-squares-of-digits; sad numbers cycle through the melancoil loop [4, 16, 37, 58, 89, 145, 42, 20]
- Parallel computation via joblib's Parallel/delayed enables multi-core sequence generation; too many processes add overhead and can slow execution
- Python recursion depth limit requires iterative rewrite or sys.setrecursionlimit for deep happification chains
Connections: Alan Zucconi · Python Programming · Recreational Mathematics
Source: http://www.alanzucconi.com/2015/11/03/recreational-maths-python/