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

 

gaurav.gupta@mq.edu.au loops > collatz
prev  |  next  |  chance

Collatz number is defined as the number of steps it takes to reduce a number to 1 using the following steps: 1. if the number is even, divide it be 2. 2. if the number is odd, multiply it by 3 and add 1 to it. Define a function that when passed an integer, returns its collatz number. You may assume the number is 1 or more.


collatz(1) → 0
collatz(20) → 7
collatz(100) → 25

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

int collatz(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: 3 Post-solution available

Copyright Nick Parlante 2017 - privacy