You will want to describe some facts exhaustively (e.g. the mapping between single digit names and values), while adding rules that describe how to build more complex number names out of simpler pieces. Hint: The first six tests above each illustrate a separate category of numbers that you will need to consider. Also, think about breaking this up into several relations when specifying your solution.?- numnames([five],X). X = 5 ; false. ?- numnames([thirteen],X). X = 13 ; false. ?- numnames([thirty],X). X = 30 ; false. ?- numnames([thirty, seven], X). X = 37 ; false. ?- numnames([two, hundred], X). X = 200 ; false. ?- numnames([nine, hundred, and, fifty, one], X). X = 951. ?- numnames(X, 375). X = [three, hundred, and, seventy, five] ; false. ?- numnames([seven], 7). true ; false.
Given:
Your predicate should behave as follows:edge(a,b). edge(b,c). edge(b,d). edge(c,e). edge(d,e). edge(e,f). edge(g,h). edge(f,a). % This new edge makes the graph cyclic
(When the last query above throws the error, press 'a' to abort the execution.)?- path_connects(a,c,P). P = [a, b, c] ; P = [a, b, c, e, f, a, b, c] ; P = [a, b, c, e, f, a, b, c, e|...] ; P = [a, b, c, e, f, a, b, c, e|...] ; P = [a, b, c, e, f, a, b, c, e|...] . ?- path_connects(a,d,[a,b,d]). true ; false. ?- path_connects(a,g,P). ERROR: Out of local stack Exception: (697,494) path_connects(c, g, _G2092467) ?
edge(a,b). edge(a,c). edge(c,d). edge(c,e). con(X,Y) :- edge(X,Y). con(X,Y) :- con(X,Z), con(Z,Y).