Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

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.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M9530233

Have any Question?


Related Questions in Programming Language

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As