program-slicing

Solving a puzzle in Prolog about time constraints

家住魔仙堡 提交于 2020-03-03 07:35:27
问题 Stuck on a Prolog problem. I know the answer (because I did it on paper first), but I cannot figure out how to get Prolog to come up with the answer. Problem: Bill eats a snack every night, having a different fruit and different nuts each night. From the statements below, identify what Bill had for a snack for each weeknight last week. a) The apple was eaten later in the week than the mango. b) The banana was eaten later in the week than both the almonds and peanuts, but earlier in the week

Einstein Riddle using Prolog

余生长醉 提交于 2019-12-31 03:17:08
问题 I'm trying to solve the Einstein riddle using Prolog. When I'm trying to run by houses(Hs), it shows No. Task is The Brit lives in the red house. The Swede keeps dogs as pets. The Dane drinks tea. The green house is on the immediate left of the white house. The green house's owner drinks coffee. The owner who smokes Pall Mall rears birds. The owner of the yellow house smokes Dunhill. The owner living in the center house drinks milk. The Norwegian lives in the first house. The owner who smokes

Printing path in Prolog

强颜欢笑 提交于 2019-12-22 10:29:04
问题 I want to print the path of nodes in a directed graph. This code works properly for an edge but didn't work for the whole path. It returns false when it comes to path. Here is my code but it is only running for just an edge and not for the whole path. Kindly help me out. Here is my code: path(Node1, Node2, X) :- edge(Node1, Node2), append([Node1], [Node2], X). path(Node1, Node2, X, N) :- edge(Node1, SomeNode), append([Node1], [SomeNode], X), path(SomeNode, Node2, X, N), append([], [Node2], X)

Adding Code of missing functions in frama-c

倖福魔咒の 提交于 2019-12-11 14:17:10
问题 Forgive my ignorance. I need to do calculate backward slices for a project. After some searching, I came across frama-c. I downloaded the package on my ubuntu system which got me Frama-c Version: Fluorine-20130601. I am trying to use it for the first time. When finding out the undefined functions in my project almost all library functions are undefined, even printf, scanf etc(Neither code nor specification for function printf). According to the tutorial, I have to add stubs for all the

Something wrong with predicate in prolog-same results for every date

匆匆过客 提交于 2019-12-11 12:47:35
问题 I have the below code in Prolog and the problem is that when i run the code it returns for every data the same result. ?- run(Diagnosis). Diagnosis='There is no problem with anemia'. The KB is in another file and load it and in start predicate i load patient3 for example and it should return Diagnosis ='Iron deficiency' Note that the start predicate is only for check if the code works right for now! When i run this file with trace it shows that first tries the first rules.. It fails in check

Prolog Family Relation, unexpected failure

爱⌒轻易说出口 提交于 2019-12-10 17:37:50
问题 Could anyone tell me why my aunt relation isn't working? It just returns false whenever I try to call it. The Uncle relation I wrote under it seems to work perfectly. I can't figure out what the difference is. I tried (not(mother(X,Y)). at the end also but that doesn't change anything. /* FACTS */ parents(david, george, noreen). parents(jennifer, george, noreen). parents(georgejr, george, noreen). parents(scott, george, noreen). parents(joanne, george, noreen). parents(jessica, david, edel).

Printing path in Prolog

我的未来我决定 提交于 2019-12-05 20:33:52
I want to print the path of nodes in a directed graph. This code works properly for an edge but didn't work for the whole path. It returns false when it comes to path. Here is my code but it is only running for just an edge and not for the whole path. Kindly help me out. Here is my code: path(Node1, Node2, X) :- edge(Node1, Node2), append([Node1], [Node2], X). path(Node1, Node2, X, N) :- edge(Node1, SomeNode), append([Node1], [SomeNode], X), path(SomeNode, Node2, X, N), append([], [Node2], X). X is a list. While @WouterBeek already pinpointed your problems, Wouter's statement Without running

Prolog - get the factors for a given number doesn't stop?

岁酱吖の 提交于 2019-12-01 05:05:53
问题 I need to find the factors of a given number , e.g : ?- divisors2(40,R). R = [40,20,10,8,5,4,2,1]. The code : % get all the numbers between 1-X range(I,I,[I]). range(I,K,[I|L]) :- I < K, I1 is I + 1, range(I1,K,L). % calc the modulo of each element with the given number : % any x%y=0 would be considered as part of the answer divisors1([],[],_). divisors1([H|T],S,X):-divisors1(T,W,X),Z is X mod H,Z==0,S=[H|W]. divisors1([_|T],S,X):-divisors1(T,S,X). divisors2(X,Result) :-range(1,X,Result1)

Logic Puzzle in Prolog - using lists

限于喜欢 提交于 2019-11-28 09:42:16
问题 I am trying to solve the following problem in Prolog, and I think I have coded it right, but my queries simply return false. Any advice on what to change? The problem is as follows: "Bagel Alley, the local bagel shop, was always a location of furious activity during the morning commute as people stopped by to get their coffee and bagel on the way to work. Fresh made on site each morning, the bagels were highly popular and the fact that the shop also had great coffee was like icing on the cake