Question: 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
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.
Step by Step Solution
3.41 Rating (151 Votes )
There are 3 Steps involved in it
cc mare act ... View full answer
Get step-by-step solutions from verified subject matter experts
