Starting from:

$30

PROLOG-Assignment 1 Simple List Processing and Arithmetic in PROLOG Solved

1.     To determine whether the first two elements of a list are same.  

2.     To determine whether a list is not a two-element list.  

3.     To determine whether two lists are of same length.  

4.     To determine length of a list using your own number system, that does not contain more than two symbols.

5.     To determine whether two lists are of same length using the length predicate developed in 4 (previous problem).

6.     To find the last element of a list.  

7.     To find whether an element is a member of a list.  

8.     To find whether two elements are next to each other in a list.

9.     To append two lists in a third list.  

10.  To find the last element of a list using append predicate developed in 9.  

11.  To find whether an element is a member of a list using append predicate developed in 9.

12.  To find whether two elements are next to each other in a list using append predicate developed in 9.  

13.  To reverse a list in another list.  

14.  To determine whether a list is a palindrome.  

 [the structure of predicate:  

                                          palindrome(L)].

15.  To find the last but one element of a list.

 

16.  To find the K'th element of a list. The first element in the list is number 1.

Example:

?- element_at(X,[a,b,c,d,e],3).

{X = c}

17.  To find the sum of all elements of a list.  

18.  To find the length of a list.

19.  To find the average of all elements of a list using sum and length defined in Problem 17 and 18.  

20.  To find the maximum number from a list.  

21.  To find gcd of two integers.

22.  To determine whether a given integer number is prime. 

[Example:

?- is_prime(7). true]

 

23.  To determine whether two positive integer numbers are coprime. 

[Two numbers are coprime if their greatest common divisor equals 1.

Example:

?- coprime(35, 64).

true]

 

24.  To determine the prime factors of a given positive integer. [Construct a flat list containing the prime factors in ascending order.

Example:

?- prime_factors(315, L).

{L = [3,3,5,7]}

            ]

 

25.  Goldbach's conjecture. 

Goldbach's conjecture says that every positive even number greater than 2 is the sum of two prime numbers. Example: 28 = 5 + 23. It is one of the most famous facts in number theory that has not been proved to be correct in the general case. It has been numerically confirmed up to very large numbers (much larger than we can go with our Prolog system). Write a predicate to find the two prime numbers that sum up to a given even integer.

              [Example:

                     ?- goldbach(28, L).

                         {L = [5,23]}

 

26.  To generate all integers between two integers N1 and N2, both N1 and N2 included and         N2N1.  

 

27.  To count numbers greater than 100.0 in a list.

 

28.  To split a list of numbers in two lists such that one contains negative numbers and other contains positive numbers.

 

29.  To find N!

 

30.  To generate first N Fibonacci numbers.

More products