Starting from:

$30

Programming Paradigms-Lab 10 Solved

Inferring types
Exercise 10.1.

Draw the search tree for the query magic(hermione).

house_elf(dobby). witch(hermione). witch('McGonagall'). witch(rita_skeeter). magic(X) :- house_elf(X). magic(X) :- wizard(X). magic(X) :- witch(X).

Crossword
Exercise 10.2.

Implement a predicate crossword/6 that solves the following crossword:

 word(astante,  a,s,t,a,n,t,e). word(astoria,  a,s,t,o,r,i,a). word(baratto,  b,a,r,a,t,t,o). word(cobalto,  c,o,b,a,l,t,o). word(pistola,  p,i,s,t,o,l,a). word(statale,  s,t,a,t,a,l,e).

Travels
Exercise 10.3.

Implement a predicate travelFromTo/2 that tells us whether we can travel (perhaps indirectly) by train between two places.

directTrain(saarbruecken,dudweiler). directTrain(forbach,saarbruecken). directTrain(freyming,forbach). directTrain(stAvold,freyming). directTrain(fahlquemont,stAvold). directTrain(metz,fahlquemont). directTrain(nancy,metz).

Paths in a graph
Exercise 10.4.

Implement a predicate path/2 that tells you whether a (directed) path exists.

connected(1,2). connected(3,4). connected(5,6). connected(7,8). connected(9,10). connected(12,13). connected(13,14). connected(15,16). connected(17,18). connected(19,20). connected(4,1). connected(6,3). connected(4,7). connected(6,11). connected(14,9). connected(11,15). connected(16,12). connected(14,17). connected(16,19).

Travel by different transport
Exercise 10.5.

Write a predicate travel/2 which determines whether it is possible to travel from one place to another by chaining together car, train, and plane journeys. For example, your program should answer true to the query travel(valmont,raglan) .

   byCar(auckland,hamilton).    byCar(hamilton,raglan). 

   byCar(valmont,saarbruecken). 

   byCar(valmont,metz).        byTrain(metz,frankfurt). 

   byTrain(saarbruecken,frankfurt). 

   byTrain(metz,paris).    byTrain(saarbruecken,paris).        byPlane(frankfurt,bangkok).    byPlane(frankfurt,singapore).    byPlane(paris,losAngeles).    byPlane(bangkok,auckland).    byPlane(singapore,auckland).    byPlane(losAngeles,auckland).

Travel by different transport: route
Exercise 10.6.

Extend the predicate travel/3 from Exercise 10.5 so that it not only tells you the route to take to get from one place to another, but also how you have to travel.

?- travel(valmont,losAngeles,X)

X  =  goByCar(valmont,metz,                  goByTrain(metz,paris,                        goByPlane(paris,losAngeles)))

More products