591 Assignment 2: Collatz's Problem
Fall 2005, David Matuszek
whileloops, and assignment statements
This is a lot to learn for a first assignment.
Consider the following algorithm, defined for positive integers:
Example: If you start with the number 17, you get the following sequence:
Does this process always terminate at one, or is there some starting number that will cause it to spiral out of control, either going into a loop or repeatedly getting larger and larger? This is called Collatz's problem, or sometimes Ulam's problem or Scott's problem (the origin isn't entirely clear). It is known that, for the first few billion integers, the process always terminates at one.
The sequences generated in this way contain 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.
Write an application that does the following:
1. 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
When you have part one working, add code to it to do the following.
You are expected to work as closely as possible with your partner. Please exchange email addresses so that you can communicate after lab is over. Try to follow the pair programming methodology as carefully as you can.
What is pair programming?
Two programmers working side-by-side, collaborating on the same design, algorithm, code or test. One programmer, the driver, has control of the keyboard/mouse and actively implements the program. The other programmer, the observer, continuously observes the work of the driver to identify tactical (syntactic, spelling, etc.) defects and also thinks strategically about the direction of the work. On demand, the two programmers can brainstorm any challenging problem. Because the two programmers periodically switch roles, they work together as equals to develop software.
-- Laurie Williams
North Carolina State University Computer Science
This is a fairly easy assignment, so some of you may finish before the end of the lab period. Future assignments will get progressively longer and more challenging.
Unless I specify otherwise, you are welcome to use any Java that both you and your partner know in doing the assignments.If you know some bit of Java you would like to use, and your partner doesn't, the best approach is to have your partner write that part, under your guidance. Both of you are expected to understand the program completely.
Turn in only one copy of the assignment, via Blackboard. Zip up the
entire BlueJ project, which should be a folder that contains the
.class files, along with a couple of other files created by
BlueJ for its own use. You and your partner should decide which of you is going
to turn in the assignment (since I want only one copy of it), but both of you
should be satisfied with it before you turn it in. Whoever turns it in, use
Blackboard's note feature to indicate who your partner is.
If you are unable to come to lab, or if you are unlucky and don't get a partner, you should complete the assignment by yourself. This will not count against you if it doesn't happen too often; however, I reserve the right to adjust grades to reflect unusually good or unusually poor teamwork skills.
If you submit a program and subsequently improve it before the due date, turn in the improved version; we will grade only the most recent version (but please try not to do this too often!). Blackboard doesn't allow you to remove earlier submissions.
If you submit a program and subsequently find errors in it after the due date, you need to decide whether you are better off correcting the errors and turning it in again with a late penalty. If you do the latter, it is a good idea to send email to us, in case grading has already happened. You should definitely correct and resubmit for serious errors, but probably not for minor glitches. Again, please avoid multiple submissions.
Thursday, September 22, before midnight.