Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

primes (Limit, Ps). :integers (2, Limit, Is), sieve (Is, Ps). integers (Low, High, [Low Rest]) :- Low = < < High, !, M is

image text in transcribed

primes (Limit, Ps). :integers (2, Limit, Is), sieve (Is, Ps). integers (Low, High, [Low Rest]) :- Low = < < High, !, M is Low+1, integers (M, High, Rest). integers (Low, High, []). sieve ([], []). sieve ([I | Is], [I]Ps]) - remove (I, Is, New), remove (P, [], []). sieve (New, Ps). remove (P, [I | Is], [I|Nis]) :- not (0 is I mod P), !, remove (P, Is, Nis). remove (P, [I Is], Nis) :- 0 is I mod P, !, remove (P, Is, Nis). Figure 4.6 The Sieve of Eratosthenes in Prolog (adapted from Clocksin and Mellish [1994])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions