Skip to main content

An algorithm that computes modular nested exponents (or towers) efficiently.

Project description

modular-towers

An algorithm that computes modular nested exponents (or towers) efficiently.

🚩 Table of Contents

🗺️ Overview

modular-towers exports a Python function mod_tower that takes as input an arbitrarily long sequence of positive integers a₁, a₂, ..., aₙ and a positive integer m and computes a₁^(a₂^(···^aₙ)) mod m efficiently (that is, without computing the value of the nested exponent).

🔧 Installing

Installing with pip is the easiest:

$ pip install modular-towers

A development version can be installed from GitHub using setuptools, provided you have sympy installed already:

$ git clone https://github.com/avivbrook/modular-towers
$ cd modular-towers
$ python setup.py install

💡 Examples

>>> from modular_towers import mod_tower as modtow
>>> modtow([6,5,4,3,2], 1948502738) # 6^(5^(4^(3^2))) mod 1948502738
951546056

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

modular-towers-0.1.tar.gz (17.0 kB view hashes)

Uploaded Source

Built Distribution

modular_towers-0.1-py3-none-any.whl (17.2 kB view hashes)

Uploaded Python 3

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