Hofstader's Q-sequence is defined by the strange-looking recurrence relation: where Q[0] = Q[1] = 1. Write...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Hofstader's Q-sequence is defined by the strange-looking recurrence relation: where Q[0] = Q[1] = 1. Write a function "q_sequence()" which takes a strictly positive integer "n" as input, and returns a list of the first n elements of this sequence. Hints: • The first few Q[n] are 1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10, 9, 10... . Do not use recursion! It will be very slow. For example: Test print (q_sequence (5)) print (q_sequence (10) ) Result [1, 1, 2, 3, 3] [1, 1, 2, 3, 3, 4, 5, 5, 6, 61 Answer: (penalty regime: 10, 20, 30, 40, 50, 60 %) Reset answer 1def q_sequence(n): 2 Q[n] = Q[n Q[n 1]] + Q[n - Q[n - 2]], # Insert your code here. Hofstader's Q-sequence is defined by the strange-looking recurrence relation: where Q[0] = Q[1] = 1. Write a function "q_sequence()" which takes a strictly positive integer "n" as input, and returns a list of the first n elements of this sequence. Hints: • The first few Q[n] are 1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10, 9, 10... . Do not use recursion! It will be very slow. For example: Test print (q_sequence (5)) print (q_sequence (10) ) Result [1, 1, 2, 3, 3] [1, 1, 2, 3, 3, 4, 5, 5, 6, 61 Answer: (penalty regime: 10, 20, 30, 40, 50, 60 %) Reset answer 1def q_sequence(n): 2 Q[n] = Q[n Q[n 1]] + Q[n - Q[n - 2]], # Insert your code here.
Expert Answer:
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
References: https://www.tbkcreative.com/ we are making a digital audit for TBK creative company please read the requirements above, pls take your time analyzing the data and name the tools used in...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
Jack is a secured creditor of Bad Loans Ltd. Jack has just received a notification that Bad Loans Ltd has appointed a voluntary administrator. Jack has no clue what this means for him. Advise Jack on...
-
Prepare journal entries to record each of the following transactions. The company records purchases using the gross method and a perpetual inventory system. June 1 9 Purchased merchandise with a...
-
The tractor and scraper units shown are connected by a vertical pin located 1.8 ft behind the tractor wheels. The distance from C to D is 2.25 ft. The center of gravity of the 20-kip tractor unit is...
-
Show that the curve with vector equation lies in a plane and find an equation of the plane. r(t) = (a,t? + b,t + c1, azt? + bzt + c2, azt? + bzt + c3) %3!
-
What makes a question bad? Develop three examples of bad questions. Rewrite your examples so they could be judged as good questions.
-
A tissue manufacturer that has the fourth-largest market share plans to experiment with a 50 off coupon during November and a buy one, get one free coupon during December. The experiment will take...
-
Adger Corporation is a service company that measures its output based on the number of customers served. The company provided the following fixed and variable cost estimates that it uses for...
-
Janet just graduated from college, has a job she's scheduled to begin in 3 months and has decided to treat herself to 6 weeks of travel across South America before she buckles down and starts working...
-
Liebeck v. McDonalds Restaurants: The Original Coffee Product Liability Case James M. Dedman, IV Back in 1994, Stella Liebeck v. McDonalds Restaurants became one of the most talked about lawsuits in...
-
What methodologies and approaches can be employed to mitigate interpersonal conflicts and enhance interpersonal cohesion within teams, thereby fortifying resilience and bolstering performance amidst...
-
what ways can synergistic team dynamics be cultivated within organizational frameworks to augment operational efficacy and foster a culture of collaborative excellence? Explain
-
In what ways, if any, does U.S. society appear to be sophistic in orientation? Your task is to respond to this question in two paragraphs. To answer this question, you should consider defining...
-
How many times have you heard the phrase"our people are our most important asset"? What does it mean, and do you agree with it? Why or why not?
-
What measures can leaders implement to mitigate the potential pitfalls of over-delegation or micromanagement, striking a delicate balance between empowerment and control to avoid burnout,...
-
Distinguish between polyp and medusa
-
Use a calculator to evaluate the expression. Round your result to the nearest thousandth. V (32 + #)
-
Given the concerns about environmental damage from car pollution, many have proposed increasing the tax on gasoline. We will consider the social benefits of such legislation later on in the text when...
-
Social Norms and Private Actions: When asked to explain our actions, we sometimes simply respond by saying it was the right thing to do. The concept of the right thing to do is one that is often...
-
Consider a simultaneous game in which both players choose between the actions Cooperate, denoted by C, and Defect, denoted by D. A: Suppose that the payoffs in the game are as follows: If both...
-
A company expects to receive which of the following benefits when it uses its budgeting process? a. The planning required to develop the budget helps managers foresee and avoid potential problems...
-
A direct materials budget would be used in which of the following types of companies? a. Service b. Merchandising c. Manufacturing d. All of the above
-
A disadvantage to merchants from accepting debit and credit cards would be a. lost sales. b. transaction fees. c. bounced checks. d. longer time to receive cash.
Study smarter with the SolutionInn App