Last active
June 19, 2021 01:47
-
-
Save EmmanuelOga/bca216ea49f6d3f00b7929757f3b2d93 to your computer and use it in GitHub Desktop.
Revisions
-
EmmanuelOga revised this gist
Jun 19, 2021 . 1 changed file with 17 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,8 @@ append(Headparts, Tailparts, Total). */ /* With accumulators: partsof(X, P) :- partsacc(X, [], P). partsacc(X, A, [X|A]) :- basicpart(X). @@ -37,3 +38,18 @@ partsacclist([P|Tail], A, Total) :- partsacc(P, A, Hp), partsacclist(Tail, Hp, Total). */ /* With difference lists: */ partsof(X, P) :- partsacc(X, P, Hole), Hole = []. partsacc(X, [X|Hole], Hole) :- basicpart(X). partsacc(X, P, Hole) :- assembly(X, Subparts), partsacclist(Subparts, P, Hole). partsacclist([], Hole, Hole). partsacclist([P|T], Total, Hole) :- partsacc(P, Total, Hole1), partsacclist(T, Hole1, Hole). -
EmmanuelOga revised this gist
Jun 19, 2021 . 1 changed file with 16 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,11 +14,26 @@ assembly(hub, [gears, axle]). assembly(axle, [bolt, nut]). /* With no accumulators: partsof(X, [X]) :- basicpart(X). partsof(X, P) :- assembly(X, Subparts), partsoflist(Subparts, P). partsoflist([], []). partsoflist([P|Tail], Total) :- partsof(P, Headparts), partsoflist(Tail, Tailparts), append(Headparts, Tailparts, Total). */ /* With accumulators: */ partsof(X, P) :- partsacc(X, [], P). partsacc(X, A, [X|A]) :- basicpart(X). partsacc(X, A, P) :- assembly(X, Subparts), partsacclist(Subparts, A, P). partsacclist([], A, A). partsacclist([P|Tail], A, Total) :- partsacc(P, A, Hp), partsacclist(Tail, Hp, Total). -
EmmanuelOga created this gist
Jun 19, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ basicpart(rim). basicpart(spoke). basicpart(rearframe). basicpart(handles). basicpart(gears). basicpart(bolt). basicpart(nut). basicpart(fork). assembly(bike, [wheel, wheel, frame]). assembly(wheel, [spoke, rim, hub]). assembly(frame, [rearframe, frontframe]). assembly(frontframe, [fork, handles]). assembly(hub, [gears, axle]). assembly(axle, [bolt, nut]). partsof(X, [X]) :- basicpart(X). partsof(X, P) :- assembly(X, Subparts), partsoflist(Subparts, P). partsoflist([], []). partsoflist([P|Tail], Total) :- partsof(P, Headparts), partsoflist(Tail, Tailparts), append(Headparts, Tailparts, Total).