Learning when and how to use a while loop, Programming Languages

1.  A function that produces the Collatz sequence and counts the number of terms.

2.  A main function that calculates interesting values about the Collatz sequence.

1.The Collatz Sequence

1. The rules for the Collatz Sequence are pretty straight forward:

3.  Start with an integer n > 1.

4.  Given a current term n, if n is even, the next term is n=2, if it is odd, the next term is 3n + 1.

5. Repeat until the last term is 1.

For examples: starting with n = 3, we get the sequence 3, 10, 5, 16, 8, 4, 2, 1.

2. It is an open question as to whether or not the sequence always returns to one for every starting value.

2. To Do and Turn In

1. The end result will be a .m file containing the main function, the Collatz function, and possibly other supporting functions.

2. The Collatz function should have one input and one output, the input is the starting number n, and the output is the number of terms in the sequence (the Collatz length), including the last term of 1. So in the example above for n = 3, the Collatz length is 8.

3. As usual, the main function will be in charge. It should be in charge of getting all the results calculated and in printing the results.

4. There are 3 results you need to produce:

(a) The Collatz length for n = 2; 3; . . .; 20 in a nice table (of course!).

(b) The first integer n for which the Collatz length is greater than 500. Display the integer and it's Collatz length.

(c) The integer n between 1 and 100 (inclusive) with the largest value for the ratio of it's Collatz length to itself. Display the integer, it's Collatz length and the ratio.

5. You'll need to figure out what kind of loop you need to use in each case.

6. As before you can have the main function do all the work (except for what the Collatz function does), or you can have subfunctions that do all or part of the work. The main function should, in any case, be totally responsible for displaying all the results.

7. When you are done, comment it well and publish the results as a PDF. Submit the PDF.

Posted Date: 3/20/2013 2:43:52 AM | Location : United States







Related Discussions:- Learning when and how to use a while loop, Assignment Help, Ask Question on Learning when and how to use a while loop, Get Answer, Expert's Help, Learning when and how to use a while loop Discussions

Write discussion on Learning when and how to use a while loop
Your posts are moderated
Related Questions
Tasks: Write a Perl script assignGrades.pl to assign letter grades to the students. Please use the classList2.txt file. Upon invoking, the script will access the file classL

Find out the selling cost average for packages developed in Pascal

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

i doing a project about depth estimation, i have done some research, and i used the block matching algorithm to get the motion vectors from the image sequences, i now have the prob

Design the proposed implementation using the contract first approach and object oriented approaches.  At a minimum, you must provide an overview of the services in the service arch

We want a program, a logic, we can list the intermediate films sandwiched between the 2 tapes (from - to) that indicates the user. example: From to

NOTE: You will only submit the University.java and EmptyFileException.java files (inside P3.zip/tar) NOTE on null objects:. From Project 1: Since the array of students in the Cou

1.   You have been asked to write a computer program that will figure out the total of an order when given the amount of the order ($200) and a sales tax rate of five percent.  I w

.NET class libraries in .NET Whether you create value in C# or VB.NET, you are getting in touch with techniques in the same .NET category your local library. The same .NET str

Define the Syntax of FOR Loop? The universal form of this statement is for(initialization;condition;increment/decrement)             { statements;             }