Sha256: 059f862f6b5bd2694e1f74c2457f831ac5c6f33e29ace3f3cf2a8d3f550be2f8

Contents?: true

Size: 259 Bytes

Versions: 94

Compression:

Stored size: 259 Bytes

Contents

def collatz_steps(n):
    if n <= 0:
        return

    step_count = 0
    while n > 1:
        if is_odd(n):
            n = n * 3 + 1
        else:
            n = n / 2
        step_count += 1

    return step_count


def is_odd(n):
    return n % 2 == 1

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
trackler-2.2.1.107 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.106 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.105 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.104 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.103 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.102 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.101 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.100 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.99 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.98 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.97 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.96 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.95 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.94 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.93 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.92 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.91 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.90 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.89 tracks/python/exercises/collatz-conjecture/example.py
trackler-2.2.1.88 tracks/python/exercises/collatz-conjecture/example.py