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

 

jebbert@volusia.k12.fl.us > quiz2023_02_28_P1SLHL_sequenceCollatz
prev  |  next  |  chance

The Collatz Conjecture in mathematics is about a recursive mathematical formula and the (believed) final result of recursively applying the formula. A Collatz sequence (or orbit) describes the specific values that are landed upon in this recursive process. So what is the specific recursive process? Here it is: Let n be a positive integer. n=1 is the base-case. No further calculations are needed. if n is even, your new number is n/2. if n is odd, your new number is 3n+1. For example, if you start with 14, the Collatz sequence (or orbit) is: 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 To make things easier, we will return a string with spaces between each number AND a space at the end. So, if your initial number 'n' is 14 you will return: "14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 " It is believed that following this process starting with any positive integer will eventually lead to 1. That is to say that it is believed that this process will never get "trapped" in some kind of repetitive loop. This seemingly simple conjecture has yet to be proven, although it is known to be true for all integers less than an extremely large number with over 1000 digits!


quiz2023_02_28_P1SLHL_sequenceCollatz(14) → "14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 "
quiz2023_02_28_P1SLHL_sequenceCollatz(16) → "16 8 4 2 1 "
quiz2023_02_28_P1SLHL_sequenceCollatz(4) → "4 2 1 "

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

public String quiz2023_02_28_P1SLHL_sequenceCollatz(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: 290

Copyright Nick Parlante 2017 - privacy