Question: Prolog Programming. a) Implement a predicate f(X, N) for a function f(n) such that f(0) = 4, f(n) = 2 * f(n-1) + 5. Please
Prolog Programming.
a) Implement a predicate f(X, N) for a function f(n) such that f(0) = 4, f(n) = 2 * f(n-1) + 5.
Please implement using RECURSION!
Test Cases:
?- f(0, N). N=4. ?- f(1, N). N=13.
b) Implement numOfHops(X, Y, N) such that Y can be reachable from X in N hops of friendships. (Use RECURSION please)
Facts: friend(alice, bob). friend(bob, charles). friend(charles, dorothy). friend(dorothy, eason).
Test cases: ?- numOfHops(alice, bob, N). N = 1. ?- numOfHops(alice, charles, N). N = 2.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
