Docsity

Assignment 1 - Principles of Programming Languages | CS 181, Assignments of Computer Science

Toggle sidebar
bg1
CS181: Programming Languages
Vladimir Vacic, Christos Koufogiannakis
University of California, Riverside
Lab Assignment 1
1. Given the following graph of possible flights between seven US cities:
(graph taken from the web site of the American Mathematical Society, http://www.ams.org)
a) Write a Prolog program that would check if there is a route from Fresno to
Dallas, from Seattle to Boston, and from Atlanta to Fresno.
b) Write a C program that does the same thing.
Note: you have to write complete, working programs, run them and show the results. As
far as C goes, the choice of data structure to store the relations between cities is yours.
Warning: if there are cycles in the graph, Prolog might never find a solution and may
never say that there are no solutions. If this happens in your assignment, make a note of
that.
pf3

Partial preview of the text

Download Assignment 1 - Principles of Programming Languages | CS 181 and more Assignments Computer Science in PDF only on Docsity!

CS181: Programming Languages Vladimir Vacic, Christos Koufogiannakis University of California, Riverside

Lab Assignment 1

  1. Given the following graph of possible flights between seven US cities:

(graph taken from the web site of the American Mathematical Society, http://www.ams.org)

a) Write a Prolog program that would check if there is a route from Fresno to Dallas, from Seattle to Boston, and from Atlanta to Fresno.

b) Write a C program that does the same thing.

Note: you have to write complete, working programs, run them and show the results. As far as C goes, the choice of data structure to store the relations between cities is yours.

Warning: if there are cycles in the graph, Prolog might never find a solution and may never say that there are no solutions. If this happens in your assignment, make a note of that.

  1. Given the partial family tree of the gods of the ancient Greeks encoded as a Prolog database:

parent(chaos, gaea). parent(gaea, cyclope). parent(gaea, chronos). parent(gaea, coeus). parent(gaea, oceanus). parent(uranus, cyclope). parent(uranus, chronos). parent(uranus, coeus). parent(uranus, oceanus). parent(chronos, hades). parent(chronos, poseidon). parent(chronos, zeus). parent(rhea, hades). parent(rhea, poseidon). parent(rhea, zeus). parent(coeus, leto). parent(phoebe, leto). parent(leto, apollo). parent(leto, artemis). parent(zeus, apollo). parent(zeus, artemis). parent(oceanus, iapetus). parent(tethys, iapetus). parent(hera, ares). parent(zeus, ares). male(chaos). male(cyclope). male(uranus). male(chronos). male(coeus). male(oceanus). male(hades). male(poseidon). male(zeus). male(ares). male(apollo). male(iapetus). female(gaea). female(rhea). female(leto). female(hera). female(phoebe). female(tethys).