Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python to program the following: Consider the two sequences P = [1,1,1] and Q = [3,0,2]. Suppose that these sequences are extended according to

Using python to program the following:

Consider the two sequences P = [1,1,1] and Q = [3,0,2]. Suppose that these sequences are extended according to formulas:

P(n+1) = P(n-1) + P(n-2)

Q(n+1) = Q(n-1) + Q(n-2)

That is, for both P and Q you ignore the most recent value, then add up the next two most recent. The first 8 values of each sequence are:

P = [1,1,1,2,2,3,4,5,...]

Q = [3,0,2,3,2,5,5,7,...].

Create a function 'provide_P(n)' that returns a list of all values in P greater or equal to n . Repeat for Q in a function 'provide_Q(n)'.

Call each function to generate lists P and Q for n = 10,000 . Use the concept of a 'set' with these lists to determine the following: a. How many unique integers are in P? How many unique integers are in Q? b. How many integers occur in both P and Q? c. How many prime integers occur in both P and Q? (Compare to a list of primes recall the Sieve of Eratosthenes.) d. There is only one number that exists in both P and Q that is not a prime. What is it? (Dont just inspect your answer to (c); work it out explicitly in code.) Hint: Once youve defined your functions, you should only need a few lines of code to answer this entire problem.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions