Task 1. Find the recursive formula for the sequence 2, 3, 6, 18, 108, 1944, ......
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Task 1. Find the recursive formula for the sequence 2, 3, 6, 18, 108, 1944, ... Then define a recursive function named mysterySequence that returns the nth member of the sequence. For example, the output for mysterySequence (4) is 108. Task 2. Spherical objects, such as tennis balls, can be stacked to form a pyramid with one tennis ball at the top, sitting on top of a square composed of four tennis balls, sitting on top of a square composed of nine tennis balls, and so forth. Write a recursive function that takes as its argument the height of a pyramid of tennis balls and returns the number of tennis balls it contains. For example: tennisBalls (3) returns 14. Task 3. Define a recursive function named decToBase2 which given an integer, returns its binary representation as a string. For example, the binary equivalent of 13 may be found by repeatedly dividing 13 by 2. So, 13 in base 2 is represented by the string "1101" and the output for decToBase2 (13) should be "1101". Task 4. Define a recursive function isDivisibleBy7 that returns true if the given number is divisible by 7, and false otherwise. For example: isDivisibleBy7(1073) returns false. To find out if a number is divisible by 7, you can follow this algorithm: Remove the last digit and double it. Subtract it from the remaining number. If the result is zero or a recognizable 2-digit multiple of 7, then the number is divisible by 7. Otherwise no or repeat if more than 2 digits are left. For example: Is 1073 divisible by 7? Remove the last digit, 3, from the number and double it, which becomes 6. The remaining number becomes 107, so 107-6 = 101. 101 has 3 digits (which is more than 2), so repeating the process one more time: remove the last digit, 1, and double it, which becomes 2. Remaining number 10-2-8. As 8 is not divisible by 7, the number 1073 is not divisible by 7. Your function *must be recursive and implement the above algorithm. You cannot use division or modulo to check for divisibility by 7 until you are down to a 2-digit number. Task 5. The famous Indian mathematician, Srinivasa Ramanujan, asked a question that stumbled a number of people: what is the value of 6+2 7+3 8+4 9+510+- carried out to infinity? Define a function, named ramanujan. Which takes, as one of its arguments, the depth of a rational approximation to the above nested expression. For example, if the depth is 0, Ramanujan should return 6. If the depth is 1, Ramanujan should return the value of 6 +27. If the depth is 2, the return value should be the value of 6 +27 + 33. Your function should implement a recursive process. Your function may have more than one argument, as needed for your recursion to work. At the end of your code, you need to give the value of the above expression when carried out to infinite. Task 6. Write a function that tests all your other functions (Task 1-5) and neatly prints out their results. The following tests should be run for each and their results printed to screen. 1. mysterySequence with n = 0, 1, 4, 7 2. tennisBalls with height = 0, 1, 3, 10 3. decToBase2 with input = 0, 1, 13, 32, 321 4. isDivisibleBy7 with input = 1, 7, 31, 1073, 1729 5. Ramanujan with depth = 1, 3, 10 These tests are not exhaustive, and I suggest you run many more tests on your own to check the functionality of each of your functions from Task 1-5. Welcome to the recursion assignment. What would you like to test? 1. mysterySequence 2. tennisBalls 3. decToBase2 4. isDivisibleBy7 5. ramanujan 6. run tests 7. Exit 1 Mystery Sequence. Please enter n to compute the nth number in sequence: 4 The 4th number in mystery sequence is 108. Welcome to the recursion assignment. What would you like to test? 1. mysterySequence 2. tennisBalls 3. decToBase2 4. isDivisibleBy7 5. ramanujan 6. run tests 7. Exit 2 Tennis Balls. Please enter the height of the pyramid: 3 A pyramid with 3 levels holds 14 tennis balls. welcome to the recursion assignment. What would you like to test? 1. mysterySequence 2. tennisBalls 3. decToBase2 4. isDivisibleBy7 5. ramanujan run tests 7. Exit Ramanujan. Enter integer depth: 7 Result at depth 7: ????? Result at infinite depth: ????? Task 1. Find the recursive formula for the sequence 2, 3, 6, 18, 108, 1944, ... Then define a recursive function named mysterySequence that returns the nth member of the sequence. For example, the output for mysterySequence (4) is 108. Task 2. Spherical objects, such as tennis balls, can be stacked to form a pyramid with one tennis ball at the top, sitting on top of a square composed of four tennis balls, sitting on top of a square composed of nine tennis balls, and so forth. Write a recursive function that takes as its argument the height of a pyramid of tennis balls and returns the number of tennis balls it contains. For example: tennisBalls (3) returns 14. Task 3. Define a recursive function named decToBase2 which given an integer, returns its binary representation as a string. For example, the binary equivalent of 13 may be found by repeatedly dividing 13 by 2. So, 13 in base 2 is represented by the string "1101" and the output for decToBase2 (13) should be "1101". Task 4. Define a recursive function isDivisibleBy7 that returns true if the given number is divisible by 7, and false otherwise. For example: isDivisibleBy7(1073) returns false. To find out if a number is divisible by 7, you can follow this algorithm: Remove the last digit and double it. Subtract it from the remaining number. If the result is zero or a recognizable 2-digit multiple of 7, then the number is divisible by 7. Otherwise no or repeat if more than 2 digits are left. For example: Is 1073 divisible by 7? Remove the last digit, 3, from the number and double it, which becomes 6. The remaining number becomes 107, so 107-6 = 101. 101 has 3 digits (which is more than 2), so repeating the process one more time: remove the last digit, 1, and double it, which becomes 2. Remaining number 10-2-8. As 8 is not divisible by 7, the number 1073 is not divisible by 7. Your function *must be recursive and implement the above algorithm. You cannot use division or modulo to check for divisibility by 7 until you are down to a 2-digit number. Task 5. The famous Indian mathematician, Srinivasa Ramanujan, asked a question that stumbled a number of people: what is the value of 6+2 7+3 8+4 9+510+- carried out to infinity? Define a function, named ramanujan. Which takes, as one of its arguments, the depth of a rational approximation to the above nested expression. For example, if the depth is 0, Ramanujan should return 6. If the depth is 1, Ramanujan should return the value of 6 +27. If the depth is 2, the return value should be the value of 6 +27 + 33. Your function should implement a recursive process. Your function may have more than one argument, as needed for your recursion to work. At the end of your code, you need to give the value of the above expression when carried out to infinite. Task 6. Write a function that tests all your other functions (Task 1-5) and neatly prints out their results. The following tests should be run for each and their results printed to screen. 1. mysterySequence with n = 0, 1, 4, 7 2. tennisBalls with height = 0, 1, 3, 10 3. decToBase2 with input = 0, 1, 13, 32, 321 4. isDivisibleBy7 with input = 1, 7, 31, 1073, 1729 5. Ramanujan with depth = 1, 3, 10 These tests are not exhaustive, and I suggest you run many more tests on your own to check the functionality of each of your functions from Task 1-5. Welcome to the recursion assignment. What would you like to test? 1. mysterySequence 2. tennisBalls 3. decToBase2 4. isDivisibleBy7 5. ramanujan 6. run tests 7. Exit 1 Mystery Sequence. Please enter n to compute the nth number in sequence: 4 The 4th number in mystery sequence is 108. Welcome to the recursion assignment. What would you like to test? 1. mysterySequence 2. tennisBalls 3. decToBase2 4. isDivisibleBy7 5. ramanujan 6. run tests 7. Exit 2 Tennis Balls. Please enter the height of the pyramid: 3 A pyramid with 3 levels holds 14 tennis balls. welcome to the recursion assignment. What would you like to test? 1. mysterySequence 2. tennisBalls 3. decToBase2 4. isDivisibleBy7 5. ramanujan run tests 7. Exit Ramanujan. Enter integer depth: 7 Result at depth 7: ????? Result at infinite depth: ?????
Expert Answer:
Related Book For
A Survey of Mathematics with Applications
ISBN: 978-0134112107
10th edition
Authors: Allen R. Angel, Christine D. Abbott, Dennis Runde
Posted Date:
Students also viewed these algorithms questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
The following is information for a perfectly price discriminating monopolist. Demand: P = 65 0.02Q Marginal revenue = P = 65 0.04Q Marginal cost = ATC = 4 Calculate the producer surplus for the...
-
The velocity is equal to the rate of change of distance x (m), (a) Substitute Eq. (1.10) and develop an analytical solution for distance as a function of time. Assume that x(0) = 0. (b) Use Euler's...
-
The DJIA reached a level of 11,722.98 in January 2000, and the S&P 500 reached a level of, 527.46 in March 2000. Prior to that, on one particular day, the DJIA was at 10,872.48 and the S&P 500 was at...
-
Explain why ocean acidification threatens shelled marine species.
-
Based on a cost-benefit analysis, management at First Community Bank decided to contract with Technology Solutions, a local data center operator, to host all of the bank's financial reporting...
-
1. Touch the pith ball with your hand. Bring an uncharged rod near it. What happens? Now charge the rubber rod and bring it near the pith ball. Explain what happens. Let it touch the ball and bring...
-
A nutrition plan app has a subscription that costs $10/month. The following chart gives average historical renewal rates for subscribers based on how many months they have been a subscriber. Month 1...
-
In the "Eating to Win" podcast, Louise Burke talks about the rise of Gatorade and Muscle Milk. Explain what her instance is on the utility of each of these products for the average individual. What...
-
List and describe the four steps in the positioning process. List the six elements of price planning and briefly describe each one.
-
How can representativeness bias, availability bias, overconfidence bias and anchoring bias can effect your decision making? Take examples from your daily life to answer the question.
-
How could you analyze and align organizational learning strategy with HR (human resources) requirements?
-
Academic Argument Assignment" As a result of your advocacy, you have been asked to present your findings on your social justice issue in a formal academic setting. This assignment asks that you...
-
How does innovation influence new product development and ultimately lead to business growth? Explain.
-
With the help of examples show that any two norms Linear on finite dimensional linear space are equivalent. n
-
Why is inventory management important for merchandising and manufacturing firms and what are the main tradeoffs for firms in managing their inventory?
-
Use a metric ruler to measure the length and width of the sides of the rectangle. Then compute the area of the rectangle. Give your answers in metric units. (Use the formula A = lw.) When...
-
Use the circle graph to answer the questions. Students at Bayshore High School were polled to determine the type of music they preferred. There were 1960 students who completed the poll. Their...
-
Subtract in the indicated base. 10012 1102
-
Compute delay, interim, and total multipliers for finite and infinite distributed lag models.
-
The mean height of American males is 69.5 inches. The heights of the 43 male U.S. presidents* (Washington through Obama) have a mean 70.78 inches and a standard deviation of 2.77 inches. Treating the...
-
Test for consistency of least squares in the ARDL representation of an infinite distributed lag model.
Study smarter with the SolutionInn App