Question: Existing function: function [M] = gen_vector(n,d) % Inputs: n m1 = 0; mf = 0; for j=1:d m1 = m1 + 10^(j-1)*1; end for j=1:d
![Existing function: function [M] = gen_vector(n,d) % Inputs: n m1 =](https://s3.amazonaws.com/si.experts.images/answers/2024/07/66a83ceb4d6d8_67466a83ceabb8e2.jpg)

![for j=1:d mf = mf + 10^(j-1)*n; end M = [m1:mf]; L](https://s3.amazonaws.com/si.experts.images/answers/2024/07/66a83cec87e77_67666a83cec26d5a.jpg)
Existing function:
function [M] = gen_vector(n,d) % Inputs: n
m1 = 0; mf = 0;
for j=1:d m1 = m1 + 10^(j-1)*1; end
for j=1:d mf = mf + 10^(j-1)*n; end
M = [m1:mf];
L = length(M); TF = M>1;
for j=1:L dig = M(j); dig_digits = zeros(1,d); dig_track = dig; for k=d:-1:1 dig_digits(1,k) = rem(dig_track, 10); dig_track = floor(dig_track/10); end for k=1:d if dig_digits(k) > n || dig_digits(k) == 0 || sum(dig_digits(k) == dig_digits) > 1 TF(j) = false; break end end end
M = M(TF);
Answer in MATLAB please
We will play a simple two-player logic game and your task is to write a function that simulates this game. In the game, the first player is the Code Maker who creates an d-digit numerical code using numbers from 1 to n (n=9). NO NUMBERS MAY BE REPEATED (and the number zero is excluded). For example: - A three digit code ( 3) using numbers from 1-6 (n=6) could be 413 - A four digit code (d=4) using numbers from 1-9 (179) could be 8295 - Etc. The second player is the Code Breaker, who is trying to crack the code set by the Code Maker. In each round, the Code Breaker makes a guess and the Code Maker returns information regarding the guess. The Code Maker returns the number of correct numbers that are in the correct spot, but does not reveal which numbers are in the right spot. The Code Breaker then guesses again. The game continues until the Code Breaker guesses the right code or until 8 guesses have been made. an exampbreaker guessses 613: CO Here's an example: Code Maker sets code 413 Round 1: Code Breaker guesses 253; Code Breaker responds with 1 (3 is in the right spot) Round 2: Code Breaker guesses 613; Code Breaker responds with 2 (1 &3 are in the right spots) Etc. YOUR FUNCTION - hw5 yourinitials func.m Your function must have two inputs: number of digits (d) and upper limit (n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
