| about | help | code help+videos | done | prefs |
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) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy