This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1 COMP348: Principles of Programming Languages Fall 2010 Assignment 1 Due date: Monday, October 18, 2010 Exercise 1 (Prolog) Consider the following graph: a b c d e f g (a) Define the Prolog facts specifying this graph. (b) Write down a Prolog program pathk(X, Y, K) returning the paths of a specific size K. For example, if the program is executed as follows: ? pathk(X, Y, 3), Prolog will return: X=a, Y=d ; X= b, Y=e ; X=a, Y=e ; X=c, Y=f ; X=d, Y=g ; false. (c) By asking Prolog the query: ? pathk(X, Y, 6), demonstrate stepbystep (unification and resolution) how this query is executed. 2 Exercise 2 (Prolog) The Fibonacci sequence is given as 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … Build a Prolog program to compute the n th Fibonacci number. (Indication: starting from the third element, each element is the sum of the two previous elements) Exercise 3 (Prolog) (a) Write down a Prolog program (we call it fela ) having as input a list and returning true if the First element of the list is Equal to the Last element. The program should return false if the input is not a list. element of the list is Equal to the Last element....
View
Full
Document
This note was uploaded on 10/25/2010 for the course CS CS 348 taught by Professor Wright,c during the Spring '10 term at Concordia Canada.
 Spring '10
 Wright,C

Click to edit the document details