Experimenting With the 3n+1 Sequence

30-minute lesson · module-lab-3n-plus-1

You are previewing this course as a guest

Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.

Sign in

Experimenting With the 3n+1 Sequence

30-minute lesson · module-lab-3n-plus-1

  • Translate a verbal rule into a `while` loop with two branches.
  • Use the counter pattern to count loop iterations.
  • Combine an outer search loop with an inner work loop to find a maximum.

Source attribution

Status: adapted

How to Think Like a Computer Scientist: Interactive Edition source · Labs / Experimenting With the 3n+1 Sequence

Adaptation notes. Original lab included an optional step using turtle graphics to plot the sequence lengths. We skip that step (PyTutor AI does not include the turtle chapter) and instead replace it with a returned-tuple challenge that surfaces both the starting value and the iteration count of the longest sequence found.

License notes. Original lab is GNU FDL 1.3 (Brad Miller and David Ranum, 2011). No verbatim text from the original is reproduced here.