1.
(25pts)
Write the following program in Prolog:
Given
a list as input, as well as a sublist to find in the first list, replace that
sublist with a third list given you.
After that, reverse the resulting list.
As an example, given the original list [a, be, cea, dee,eee,f,g], a
search sublist [dee,eee,f], and a replacement list [sar,ci,fer], you should
return the list [g,fer,ci,sar,cea,be,a].
2.
(10
pts) Using Python, write a program that
will read a string from a file and count the number of each letter appearing in
the string read from that file. The file
MUST use a dictionary to hold the counts for each letter. The name of the file will be entered from the
keyboard. At the end of the program,
write out a list of the letter and its’ count with ONE letter and count per
line.
3.
(25pts) Write the predicates in Prolog that will calculate x!.
4.
(25pts) Compare BASIC, Prolog, and Python in terms of
math, type casting, indenting, ease of use, and optimization.
3. (25pts) Write the predicates in Prolog that will calcualte x!.
ReplyDeletefactorial(0,Y) :- 0.
factorial(X,Y) :- Y is X*NewX,
NewX is X-1,
factorial(NewX,Y).