|CIT 591 Assignment 2: Scott's Problem
Consider the following problem, defined for positive integers:
- Choose a number.
- Repeatedly do the following:
- If the number is 1, quit, otherwise
- If the number is even, cut it in half.
- If the number is odd, multiply it by 3 and add 1.
Example: If you start with the number 17, you get the following sequence:
- 17 -- this is odd, so multiply by 3 and add 1, getting 52
- 52 -- this is even, so divide by 2, getting 26
- 26 -- this is even, so divide by 2
- 13 -- this is odd, so multiply by 3 and add 1
- 40 -- this is even
- 20 -- this is even
- 10 -- this is even
- 5 -- this is odd
- 16 -- this is even
- 8 -- this is even
- 4 -- this is even
- 2 -- this is even
- 1 -- stop
Does this procedure eventually reach 1 and stop for every choice of
starting number? So far, this is an unsolved problem--no one has yet proved
that the process always results in 1, and no one has yet found a counterexample.
Your assignment: Write an application (not an applet) that does the
Scott's problem has not been "solved," and if you spend any time with
it, you will start to discover some fascinating patterns. If this is the sort
of problem that appeals to you, the computer is a great way to help discover some
of these patterns.
- Prints out your name, followed by a blank line.
- For each of the numbers 1 through 20, print out a line that begins with
the number, then a colon and space, then the sequence of numbers that results
from starting with the given number. Separate the numbers by spaces. For example,
starting from the number 17, you would print the single line:
17: 52 26 13 40 20 10 5 16 8 4 2 1
- For extra neatness, you can make the numbers line up better by inserting
an extra space before each single-digit number (a number less than 10).