1. Write the following as a set of Prolog predicates: Eat at the restaurant if it looks nice but if it stinks don't eat there using: (a) cut and fail combination (b) the 'not' predicate. ============ 2. Consider the following program which is supposed to insert its first argument, a number, into its second argument, a sorted list, giving the third argument (also a sorted list): insert(X,[H|T],[H|T1]) :- X>H, !, insert(X,T,T1). insert(X,L,[X|L]). 1. Provide an appropriate query to show that this program is incorrect 2. Change the program so that it works correctly ============ 3. Write a ternary predicate delete_all(item,list,result) that is true if result is obtained from list by deleting all occurrences of item. Use cut to prevent backtracking. Sample run: ?-delete_all(a,[a,b,c,a,d,a],X). X=[b,c,d]; No ?-delete_all(a,[b,c,d],X). X=[b,c,d]; No ============= 4. Write a binary predicate count_occurrences(input,result) that is true if 'result' is a list of two-element lists [el, number_of_occurrences_in_input], where 'el' is an element of the list 'input', and 'number_of_occurrences_in_input' is an integer specifying how many times 'el' occurs in 'input'. For each element 'el' in 'input' there should be a corresponding pair [el, number_of_occurrences_in_input] in 'result'. Sample run: ?- count_occurrences([a,b,a,a,b,c],X). X = [[c, 1], [b, 2], [a, 3]] ; No ============= 5. Write a ternary predicate delete_nth that deletes every N'th element from a list. Sample runs: ?- delete_nth([a,b,c,d,e,f],2,L). L = [a, c, e] ; No ?- delete_nth([a,b,c,d,e,f],1,L). L = [] ; No ?- delete_nth([a,b,c,d,e,f],0,L). No ?- delete_nth([a,b,c,d,e,f],10,L). L = [a, b, c, d, e, f] ; No