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

A Notepad File Edit Format View Help Start with 2 int arrays, a and b, of any le

ID: 3906013 • Letter: A

Question

A Notepad File Edit Format View Help Start with 2 int arrays, a and b, of any length. Return how many of the arrays have 1 as their first element. start1([1, 2, 3], [1, 3]) 2 start1(17, 2, 3, [1) 1 starti (I1,2, [ 1 ts length 3, return a new array with the elements in reverse order, so (1, 2, 3) becomes (3, 2, 1). reverse3(1, 2, 31) [3, 2, 1] reverse3(I5, 11, 9]) [9, 11, s] reverseX(7, e, e])-[e, e, 7] 3- Given an array of ints, return true if the array is length 1 or more, and the first element and the last element are equal. sameFirstlast([1, 2, 3]) false sameFirstLast([1, 2, 3, 1]) true sameFirstLast([1, 2, 1]) true 4-Return the number of even ints in the given array, Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1. countEvens([2, 1, 2, 3, 4]) 3 countEvens ([2, 2, e])3 countEvens([1, 3, 5) 0

Explanation / Answer

Please find the Prolog codes below:-

Q3)

reverse3([],Z,Z).

reverse3([H|T],Z,Acc) :- reverse3(T,Z,[H|Acc]).

Q4)

Samefirstlast([H,H]).
Samefirstlast([F,_|T]) :- Samefirstlast([F|T]).

Please let me know in case of any clarifications required. Thanks!

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