id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

collatz


Given a positive integer n, apply the Collatz conjecture to it: as long as n is not 1, if it is even then divide it by 2 (using // for integer division), if it is odd then multiply it by 3 and add 1. Return the number of divisions you need to apply in this way to reach 1. All examples are guaranteed to reach 1 eventually.


collatz(2) → 1
collatz(3) → 5
collatz(6) → 6

...Save, Compile, Run (ctrl-enter)

def collatz(n):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Copyright Nick Parlante 2017 - privacy