Question

Define in Scheme an infinite stream consisting of all pairs of twin prime numbers, i.e. all...

Define in Scheme an infinite stream consisting of all pairs of twin prime numbers, i.e. all pairs of prime numbers differing by 2, listed in increasing order according to the first number of a pair, in every pair the first item being smaller than the second item. Hint: Apply the sieve of Eratosthenes in order to construct a predicate is-prime?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In the given question, an infinite stream consist of two pair. Suppose infinite stream is n. Then we have to find out the pair of all two prime numbers that 1 to n. So the prime number like 3, 5, 7. All the prime numbers difference will be 2 and first number will be smaller than the second number like pair would be (3, 5)(5, 7)(11,13) and so on. So (2,3) is not accepted here because of distance is 1.

Solution of the problem in scheme:

  • First of all find the list of all prime numbers which is equal to infinite stream n or smaller than n. After repeat this process till the n number. Then check 1st number suppose its kth number and 2nd number will be (k+2)th number after that check both kth and (k+2)th numbers are prime or not if its prime then it will print the both number like this (3, 5)(5, 7)(11,13) or else it will go to the next number to find out the twin prime or not.

Example:

Input: 35.
Output :(3, 5), (5, 7), (11, 13), (17, 19) (29, 31).

Other example:

Input : nth numbers.

Output:(3, 5), (5, 7), (11, 13)........(n-2, n).

*Please give an upvote if you find this solution helpful.

Add a comment
Know the answer?
Add Answer to:
Define in Scheme an infinite stream consisting of all pairs of twin prime numbers, i.e. all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT