Skip to main content

A collection of functions to play with Lychrel numbers and other funny mathematical problems

Project description

Lychrel

PyPI version Documentation Status

This is a collection of python functions which implements famous mathematical problems, and it is named after the lychrel numbers.

Under the hood lychrel is implemented in rust thanks to PyO3.

User guide and documentation: lychrel.readthedocs.io

Any contribution is welcome!

Implemented algorithms

  • Lychrel numbers: find first palindrome of the reverse-and-add procedure and determine if a number is a lychrel candidate.
  • Generalized fibonacci sequences: also known as Lucas Sequence.
  • Read out and loud: Given a number, this function compute the sequence of digits resulting from reading out loud the number, grouping together multiples of the same digit if any. E.g. read_out_loud(3211) == 131221 because the number 3211 is read as "one 3, one 2 and two 1s".
  • Kaprekar's routine: an iterative algorithm that, with each iteration, takes a natural number in a given number base, creates two new numbers by sorting the digits of its number by descending and ascending order, and subtracts the second from the first to yield the natural number for the next iteration.
  • Collatz conjecture: also known as 3n+1 problem, implements an iterator given a starting number. E.g. list(collatz(5)) == [5, 16, 8, 4, 2, 1].

Getting started

Lychrel is available on PyPi, to install it just type on your favourite shell:

pip install lychrel

Install from source

If you want to install lychrel from source code, clone this repo and create a virtual environment with python 3.7+ using your favourite tool (conda, virtualenv, etc.), then follow these steps:

1. Install dev requirements

pip install -r requirements-dev.txt

2. Build the package

maturin develop

For optimal performances add the --release option:

maturin develop --release

Examples

Check whether a number is a lychrel candidate:

from lychrel import is_lychrel_candidate

assert is_lychrel_candidate(196)
assert not is_lychrel_candidate(197)

Check out the tests for more examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lychrel-0.7.2.tar.gz (13.3 kB view hashes)

Uploaded Source

Built Distributions

lychrel-0.7.2-cp37-abi3-win_amd64.whl (162.5 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

lychrel-0.7.2-cp37-abi3-win32.whl (150.3 kB view hashes)

Uploaded CPython 3.7+ Windows x86

lychrel-0.7.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

lychrel-0.7.2-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.4 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

lychrel-0.7.2-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

lychrel-0.7.2-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

lychrel-0.7.2-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

lychrel-0.7.2-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.5+ i686

lychrel-0.7.2-cp37-abi3-macosx_11_0_arm64.whl (289.6 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

lychrel-0.7.2-cp37-abi3-macosx_10_7_x86_64.whl (299.4 kB view hashes)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page