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

 

orion.a.smith@gmail.com apcsa-recursion > apcsaRecurCollatz
prev  |  next  |  chance

Given a positive integer, recursively apply a step of the Collatz sequence. Each step obeys the following rules:


-If the number is even, divide it by 2.

-If the number is odd, multiply it by 3 and add 1.

Return how many steps it takes to reach the number 1.

apcsaRecurCollatz(1) → 0
apcsaRecurCollatz(2) → 1
apcsaRecurCollatz(3) → 7

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

public int apcsaRecurCollatz(int 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

Java Help

Misc Code Practice

Difficulty: 350

Copyright Nick Parlante 2017 - privacy