Skip to main content

Iterate over sums of a certain number of elements

Project description

Info:

This is the README file for Sum walker.

Author:

Shlomi Fish <shlomif@cpan.org>

Date:
2020-02-25
Version:
0.6.1
https://travis-ci.org/shlomif/sum_walker.svg?branch=master

PURPOSE

The sum_walker PyPI distribution allows one to iterate over increasing sums of a certain number (e.g: 2 or 3) of elements out of a stream of increasing integers.

INSTALLATION

pip3 install sum_walker

USAGE

# Finding sums of 2 powers of 3:
# https://en.wikipedia.org/wiki/Taxicab_number
from sum_walker import DWIM_SumWalker

seq = [0, 1]
reached = 2

def request_more():
    nonlocal reached
    nonlocal seq
    seq.append(reached ** 3)
    reached += 1

it = DWIM_SumWalker(2, seq, request_more)
for sum_, coords in it:
    len_ = len(coords)
    if len_ > 1:
        print("{}   {}      {}".format(
            len_, sum_, " ; ".join(
                [" + ".join(["{} ** 3".format(x) for x in c])
                 for c in coords])))

NOTES

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

sum_walker-0.6.1.tar.gz (13.1 kB view hashes)

Uploaded Source

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