Question: use SWI-Prolog to do the problem, show the program screenshots Problem 1: implement height(List, H) using recursion. Do NOT use assert! % Input: List -
use SWI-Prolog to do the problem, show the program screenshots
Problem 1: implement height(List, H) using recursion. Do NOT use assert!
% Input: List - list of blocks/cubes in a tower.
% Assume: length of side of each block/cube is stored as fact:
% side(Cube, Length).
% Output: H - total height of stack of blocks. See examples.
% test data for blocks a, b, c:
side(a, 1).
side(b, 2).
side(c, 3).
% test cases to demonstrate your program:
% ?- height([a, b, c], H).
% H = 6. (Prolog automatically gives value of variable.)
% ?- height([ ]), H).
% H = 0.
% ?- height([a, a, a, a, b], H).
% H = 6.
% Type your solution here:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
