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

 

david.white@denison.edu cs111fall2019 > collatz
prev  |  next  |  chance

A Collatz sequence is a sequence of integers starting with n where the next element is n/2 if n is even and 3*n + 1 if n is odd. An unproven conjecture is that the sequence always gets to 1 at some point, regardless of what number it starts with. Write the function collatz(n) that returns the sequence starting with n and ending with 1.


collatz(1) → [1]
collatz(2) → [2, 1]
collatz(3) → [3, 10, 5, 16, 8, 4, 2, 1]

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

def collatz(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

Python Help

Difficulty: 240 Post-solution available

Copyright Nick Parlante 2017 - privacy