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

Your task is to implement a MATLAB version of the guess the number function exce

ID: 3579161 • Letter: Y

Question

Your task is to implement a MATLAB version of the guess the number function except this one:

1: Is played on an n-dimensional board.

2. You must meet strict complexity requirements.

Your function must have the following signature:

function y = play(a, b, f)

Where:

x == -1 %guess too low

x == 0 %guess correct

x == 1 %guess to high

1. a is row vector of length n for n > 0.

2. b is row vector with length(a) == length(b)

3. f is the oracle.

4. The unknown point has integer coordinates and is in the rectangle with lower-left corner a and upper-right corner b.

Hint: You will need a loop-within-loop structure.

Explanation / Answer

y = 1;
b = 10;
while(ne(y,0))
a = input('Enter your guess: ');
if(ge(a,b))
y = 1;
fprintf('Guess is too high ');
elseif(le(a,b))
y = -1;
fprintf('Guess is too low ');
else
if(eq(a,b))
y = 0;
fprintf('Guess is correct');
break;
end
end
end