Skip to main content

Convert the given Python code into an equivalent code without for/while loops

Project description

loop-to-recursion

Test

Description

Convert the given Python code into an equivalent code without for/while loops

Install

pip install loop-to-recursion

Usage

$ cat sample.py
def function(x):
    l, r = 0, x + 1
    while r - l != 1:
        m = (r + l) // 2
        if x < m * m:
            r = m
        else:
            l = m
    return l
$ loop-to-recursion sample.py
$ cat sample.py
def function(x):
    m = None
    l, r = (0, x + 1)

    def _while_1(m, r, l, /):
        if r - l != 1:
            m = (r + l) // 2
            if x < m * m:
                r = m
            else:
                l = m
            return _while_1(m, r, l)
        else:
            return (m, r, l)
    m, r, l = _while_1(m, r, l)
    return l

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

loop_to_recursion-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loop_to_recursion-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file loop_to_recursion-0.1.1.tar.gz.

File metadata

  • Download URL: loop_to_recursion-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for loop_to_recursion-0.1.1.tar.gz
Algorithm Hash digest
SHA256 20f915aed7b3e424793536d335016e958d4c364c2b51eca4306be4d6510fd578
MD5 69e2a7fa4c5f44762c27ac2f263721eb
BLAKE2b-256 021be376eac3e92bfca8154800eb6e7895ff660baa0964260ddbc9ce6bd5613e

See more details on using hashes here.

Provenance

The following attestation bundles were made for loop_to_recursion-0.1.1.tar.gz:

Publisher: publish.yml on koyuki7w/loop-to-recursion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file loop_to_recursion-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for loop_to_recursion-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1a63797f32223f96bb2eebeaca8a463dbf3bb82727596b0aaaa6f563e416053
MD5 68737661c3a11bc0b61ea554bbf76e53
BLAKE2b-256 c8df2e790cdbb4ae3bbfd42b21c324735e996554db84871e1aff1c62368110ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for loop_to_recursion-0.1.1-py3-none-any.whl:

Publisher: publish.yml on koyuki7w/loop-to-recursion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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