Question: Using Prolog create these simple functions A)=, write a function, hlbackwards, that takes a list as input, and returns a list in which the elements

Using Prolog create these simple functions

A)=, write a function, hlbackwards, that takes a list as input, and returns a list in which the elements of the toplevel list are in reverse order.

B) write a function, llbackwards, that takes a list as input, and returns a list in which every list and sublist is in reverse order.

C)

Write a function, palindrome, that takes a list as input and returns the original list if the list is a palindrome, ie reads the same in both directions, and otherwise returns the original list made into a palindrome by reversing it and appending it to itself, but not replicating the last element. Here is a sample run:

?- palindrome([a,b,[c,d],e],X).

X=[a,b,[c,d],e,[d,c],b,a]

?- palindrome([a,[b,c,[d]],[[d],c,b],a],X).

X=[a,[b,c,[d]],[[d],c,b],a]

?-

D) Write a function, permutations, that takes a list as input and generates a list containing all possible permutations of the list elements.

E)

rite a function, ionah, that takes a single number as input and prints out the solution to the inverted disk problem for that many disks. This is the problem of moving a stack of k disks of increasing size from bottom to top, from the first peg to the third peg with another peg that may be used as well, subject to the condition that a smaller disk is never put on top of a larger one, and only one disk may be moved at a time. Here is a sample run:

?- ionah(3).

move disk from peg 1 to peg 3

move disk from peg 1 to peg 2

move disk from peg 3 to peg 2

move disk from peg 1 to peg 3

move disk from peg 2 to peg 1

move disk from peg 2 to peg 3

move disk from peg 1 to peg 3

Yes

?-

F)Write a function, sequence, that takes a single integer as input and prints out a list containing that many terms of the sequence defined by:

G) Write a program to argue with yourself. Your program should take statements that are typed in as a list and change the pronouns and negate them. For instance, you should change to I, are should change to am not, and so on.

H) Write a function, bubblesort, that takes a list of numbers as input and returns the list sorted in ascending order using a bubblesort.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!