CKP

Pure Python implementations of competitive programming algorithms.

View the Project on GitHub 123jimin/ckp

CKP

CKP is a Python library providing various algorithms for solving competitive programming problems.

Features

Examples

Here’s a simple code for computing sum of all prime numbers under $10^7$:

from ckp.number_theory import PrimeSieve

# Prints "3203324994356".
print(sum(PrimeSieve(10_000_000).primes()))

Installation

CKP is not yet on PyPI, so you need to get CKP from GitHub.

Using PIP

pip install git+https://github.com/123jimin/ckp.git

Using Poetry

I recommend using Poetry to manage Python packages.

poetry add git+https://github.com/123jimin/ckp.git

Library Index

Below is the list of submodules CKP provides. Click on a header to check API available under the module.

It’s generally preferred to import one or more of the sub-packages, rather than doing import ... from ckp.

Number Theory: ckp.number_theory

Contains various functions related to number theory, mostly for working on a finite field $\mathbb{F}_p$.

Linear Algebra: ckp.linear_algebra

Strings: ckp.string

Data Structures: ckp.data_structure

Graph Theory: ckp.graph_theory

Note: graph data structures themselves are under ckp.data_structure.graph, not under this module.

Tree Graphs: ckp.graph_theory.tree

Fourier Transformation: ckp.fourier

Contains various functions for discrete Fourier transformation (DFT).

Automata: ckp.automata

Contains algorithms related to finite-state automata.

Geometry: ckp.geometry

Contains various algorithms and functions for 2D and 3D geometry.

Numeric: ckp.numeric

Contains various constants and algorithms for computing numeric functions.

Nimber: ckp.nimber

Contains nimber arithmetic, which is just an another name for the Galois field $GF(2^{2^k})$.

Miscellaneous: ckp.misc

Contains several niche algorithms that aren’t used much.

Not in CKP

Following algorithms are not implemented in CKP, mostly because the Python Standard Library already provides an implementation.

Caveats

Many parts of CKP are work-in-progress.

There’s no guarantee on API stability. No backwards compatibility is provided.

Using CKP for purposes other than competitive programming is not recommended. Consider using another library, implementing your own C extension, or using another language.

License

CKP is licensed under the MIT license: https://github.com/123jimin/ckp/blob/main/LICENSE