Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Prolog create these simple functions A)=, write a function, hlbackwards, t

ID: 3718980 • Letter: U

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 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.

Explanation / Answer

Hi,
Its against chegg policy to post multiple questions as one, please post others as separate questions
A)
reverse([],[]). %this is base case, empty llist case
reverse([H|T], RevList):-
reverse(T, RevT), conc(RevT, [H], RevList). %this is basically concatenating with head, the reverse of the remaining list
for example the list is [a,b,c,d]
the tail of list is [b,c,d] whose reverse is [d,c,b] and this appended with head is [d,c,b,a] which is our final result

Thumbs up if this was helpful, otherwise let me know in comments

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote