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

Assignment Help:

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.


Related Discussions:- Learning when and how to use a while loop

Implement a two-dimensional table in prolog, Implement a two-dimensional ta...

Implement a two-dimensional table in Prolog. Your program will contain: 1.  An insert_entry predicate that takes a table, row, column and an entry and inserts the entry at the g

Abstraction hierarchy of mechanisms, Abstraction hierarchy of mechanisms ...

Abstraction hierarchy of mechanisms Given  the light-sensitive the motor and resistor,  we could  find  several  ways  of interconnecting them, using bits of ceramic and metal

Python , Return a new picture with each pixel''s color values made up of 80...

Return a new picture with each pixel''s color values made up of 80% of the color values of the corresponding pixel in the first picture and 20% of the color values of the

Maximization, A company produces three sizes of window fans small, medium a...

A company produces three sizes of window fans small, medium and large. the manager has formulated an LP model for fan production Maximize 6x1+8x2+5x3

C, Is it possible to get an assignment done within 2 hours

Is it possible to get an assignment done within 2 hours

Identify the type of addressing, specify the function of the instruction an...

specify the function of the instruction and also specify whether its right or wrong-: (5) 1) MOV [BX],AX? Register Indirect addressing 2) MOV CX,[BX+DI]?Base plus index add

Create a clickable map - web operating system, You are required to develop ...

You are required to develop a content management system for the following scenario:   "A Travel Information (NTIK) system is to be designed to allow travellers to access to an elec

Kinect help, My kinect hand cursor only works for main menu but when it go...

My kinect hand cursor only works for main menu but when it goes to another page it wouldn''t work.. especially when there is for camera feed

Pseudocode for a program that reads a temperature, Write a pseudocode for a...

Write a pseudocode for a program that reads a temperature as a whole number from a user and outputs a “probable” season (winter, sprint, summer, or fall) depending on the temperatu

Ws-addressing, WS-Addressing, WS-Reliable Texting and WS-Security WCF tools...

WS-Addressing, WS-Reliable Texting and WS-Security WCF tools many innovative Web solutions (WS) expectations such as WS-Addressing, WS-Reliable Texting and WS-Security. With the di

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd