neighbours(devon,cornwall). neighbours(devon,dorset). neighbours(devon,somerset). neighbours(avon,somerset). neighbours(avon,wiltshire). neighbours(avon,gloucestershire). neighbours(dorset,wiltshire). neighbours(somerset,wiltshire). neighbours(gloucestershire,wiltshire). neighbours(dorset,somerset). neighbours(dorset,hampshire). neighbours(hampshire,wiltshire). neighbours(hampshire,berkshire). neighbours(hampshire,sussex). neighbours(hampshire,surrey). neighbours(sussex,surrey). neighbours(sussex,kent). neighbours(london,surrey). neighbours(london,kent). neighbours(london,essex). neighbours(london,hertfordshire). neighbours(london,buckinghamshire). neighbours(surrey,buckinghamshire). neighbours(surrey,kent). neighbours(surrey,berkshire). neighbours(oxfordshire,berkshire). neighbours(oxfordshire,wiltshire). neighbours(oxfordshire,gloucestershire). neighbours(oxfordshire,warwickshire). neighbours(oxfordshire,northamptonshire). neighbours(oxfordshire,buckinghamshire). neighbours(berkshire,wiltshire). neighbours(berkshire,buckinghamshire). neighbours(gloucestershire,worcestershire). neighbours(worcestershire,herefordshire). neighbours(worcestershire,warwickshire). neighbours(bedfordshire,buckinghamshire). neighbours(bedfordshire,northamptonshire). neighbours(bedfordshire,cambridgeshire). neighbours(bedfordshire,hertfordshire). neighbours(hertfordshire,essex). neighbours(hertfordshire,cambridgeshire). neighbours(hertfordshire,buckinghamshire). neighbours(buckinghamshire,northamptonshire). distance(plymouth,exeter,42). distance(exeter,bournemouth,82). distance(bristol,taunton,43). distance(bristol,gloucester,35). distance(torquay,exeter,23). distance(plymouth,torquay,24). distance(bristol,bath,13). distance(exeter,taunton,34). distance(penzance,plymouth,78). distance(taunton,bournemouth,70). distance(bournemouth,salisbury,28). distance(taunton,salisbury,64). distance(salisbury,bath,40). distance(bath,gloucester,39). distance(bournemouth,bath,65). distance(truro,penzance,26). distance(plymouth,truro,52). distance(shaftesbury,salisbury,20). distance(sherbourne,shaftesbury,16). distance(dorchester,bournemouth,28). distance(salisbury,winchester,24). distance(exeter,sherbourne,53). distance(sherbourne,taunton,29). distance(bath,cirencester,32). distance(cirencester,cheltenham,16). distance(cheltenham,gloucester,9). distance(dorchester,sherbourne,19). distance(bath,shaftesbury,33). distance(winchester,bournemouth,41). distance(exeter,dorchester,53). distance(athens,bristol,60). county(bristol,avon). county(taunton,somerset). county(salisbury,wiltshire). county(bath,avon). county(bournemouth,dorset). county(gloucester,gloucestershire). county(torquay,devon). county(penzance,cornwall). county(plymouth,devon). county(exeter,devon). county(winchester,hampshire). county(dorchester,dorset). county(cirencester,gloucestershire). county(truro,cornwall). county(cheltenham,gloucestershire). county(shaftesbury,dorset). county(sherbourne,dorset). size([],0). size([X|Tail],N) :- size(Tail,N1), N is N1+1. % Answer to question (i) give(County) :- bagof(X,neighbours(X,County),L), size(L,N), N>=3 ; bagof(X,neighbours(County,X),L), size(L,N), N>=3. % Answer to question (ii) distance1(Town):- distance(bristol,Town,D), D<65. distance2(Town):- distance(Town,bristol,D), D<65. printlist(List):- findall(Town,distance1(Town),List1), findall(Town,distance2(Town),List2), conc(List1,List2,List). % Answer to question (iii) not(P):- call(P),!,fail ; true. member(X,[X|T]). member(X,[H|T]):- member(X,T). adjacent(X,Y):- neighbours(X,Y) ; neighbours(Y,X). path(A,Z,Path):- path1(A,[Z],Path). path1(A,[A|Path1],[A|Path1]). path1(A,[Y|Path1],Path):- adjacent(X,Y), not(member(X,Path1)), path1(A,[X,Y|Path1],Path).