Write PROLOG programs:
- To determine whether the first two elements of a list are same.
- To determine whether a list is not a two-element list.
- To determine whether two lists are of same length.
- To determine length of a list using your own number system, that does not contain more than two symbols.
- To determine whether two lists are of same length using the length predicate developed in 4 (previous problem).
- To find the last element of a list.
- To find whether an element is a member of a list.
- To find whether two elements are next to each other in a list.
- To append two lists in a third list.
- To find the last element of a list using append predicate developed in 9.
- To find whether an element is a member of a list using append predicate developed in 9.
- To find whether two elements are next to each other in a list using append predicate developed in 9.
- To reverse a list in another list.
- To determine whether a list is a palindrome.
[the structure of predicate:
palindrome(L)].
- To find the last but one element of a list.
- To find the Kth 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}
- To find the sum of all elements of a list.
- To find the length of a list.
- To find the average of all elements of a list using sum and length defined in Problem 17 and 18.
- To find the maximum number from a list.
- To find gcd of two integers.
- To determine whether a given integer number is prime.
[Example:
?- is_prime(7). true]
- 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]
- 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]}
]
- Goldbachs conjecture.
Goldbachs 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]}
- To generate all integers between two integers N1 and N2, both N1 and N2 included and N2>N1.
- To count numbers greater than 100.0 in a list.
- To split a list of numbers in two lists such that one contains negative numbers and other contains positive numbers.
- To find N!
- To generate first N Fibonacci numbers.
Reviews
There are no reviews yet.