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

 

orion.a.smith@gmail.com apcsa-loops > apcsaLoopsCollatzSequence
prev  |  next  |  chance

Given a positive integer, repeatedly 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.


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

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

public int apcsaLoopsCollatzSequence(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: 210

Copyright Nick Parlante 2017 - privacy