prtpy - Number Partitioning

0.8.3 · active · verified Fri Apr 17

prtpy is a Python library for number partitioning. It provides various algorithms to divide a list of numbers into a specified number of subsets, typically aiming to minimize the largest sum of a subset. It is actively maintained, with the current version being 0.8.3, and releases occur as new algorithms, improvements, or bug fixes are introduced.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `prtpy` to partition a list of numbers into a specified number of bins using the greedy algorithm. The `partition` function acts as a general interface, accepting the algorithm as a parameter.

from prtpy import partition
from prtpy.partition import greedy

numbers = [3, 4, 5, 6, 7, 8, 9, 10]
num_bins = 3

# Partition the numbers into 3 bins using the greedy algorithm
result = partition(algorithm=greedy, num_bins=num_bins, items=numbers)

print(f"Original numbers: {numbers}")
print(f"Number of bins: {num_bins}")
print(f"Partition result (greedy): {result}")
# Expected output for the given input might be similar to: [[10, 8, 3], [9, 7, 4], [6, 5]]

view raw JSON →