A pincode consists of N integers between 1 and 9. In a valid pincode, no integer is allowed to repeat consecutively. Ex: The sequence 1, 2,1, 3 is valid because even though 1 occurs twice, it is not consecutive. However, the sequence 1, 2, 2, 1 is invalid because 2 occurs twice, consecutively. Utilize a for loop and branch statements to write a function called pinCodeCheck to detect and eliminate all the consecutive repetitions in the row array pinCode. The function outputs should be two row arrays. The row array repPos contains the positions pinCode where the consecutive repeats occurs, and the row array pinCodeFix is a valid pincode with all the consecutive repeats removed in pinCode. Hint: The empty array operator [] is will be helpful to use.

Answers

Answer 1
Answer:

Answer:

function [ repPos, pinCodeFix ] = pinCodeCheck( pinCode )

       pinCodeFixTemp = pinCode;

       repPosTemp = [];

   for i = 1:length(pinCode)

       if((i > 1)) & (pinCode(i) == pinCode(i - 1))

           repPosTemp([i]) = i;

       else

           repPosTemp([i]) = 0;

       end

   end

   for i = 1:length(pinCode)

       if(repPosTemp(i) > 0)

           pinCodeFixTemp(i) = 0;

       end

   end

   repPosTemp = nonzeros(repPosTemp);

   pinCodeFixTemp = nonzeros(pinCodeFixTemp);

   repPos = repPosTemp';

   pinCodeFix = pinCodeFixTemp';

   

end

Explanation:

Let me start off by saying this isn't the most efficient way to do this, but it will work.

Temporary variables are created to hold the values of the return arrays.

       pinCodeFixTemp = pinCode;

       repPosTemp = [];

A for loop iterates through the length of the pinCode array

       for i = 1:length(pinCode)

The if statement checks first to see if the index is greater than 1 to prevent the array from going out of scope and causing an error, then it also checks if the value in the pinCode array is equal to the value before it, if so, the index is stored in the temporary repPos.

        if((i > 1)) & (pinCode(i) == pinCode(i - 1))

        repPosTemp([i]) = i;

Otherwise, the index will be zero.

         else

         repPosTemp([i]) = 0;

Then another for loop is created to check the values of the temporary repPos to see if there are any repeating values, if so, those indexes will be set to zero.

         for i = 1:length(pinCode)

         if(repPosTemp(i) > 0)

         pinCodeFixTemp(i) = 0;

Last, the zeros are removed from both temporary arrays by using the nonzeros function. This causes the row array to become a column array and the final answer is the temporary values transposed.

         repPosTemp = nonzeros(repPosTemp);

         pinCodeFixTemp = nonzeros(pinCodeFixTemp);

         repPos = repPosTemp';

         pinCodeFix = pinCodeFixTemp';


Related Questions

When you assign a(n) ____ to a field, Access will display the value you assign, rather than the field name, in datasheets and in forms.?
Find the difference between the product of 26.22 and 3.09 and the sum of 3.507,2.08,11.5, and 16.712
You are in charge of recycling computers. some of the computers have hard drives that contain personally identifiable information (pii). what should be done to the hard drive before it is recycled?
A network administrator wants to increase the speed and fault tolerance of a connection between two network switches. To achieve this, which protocol should the administrator use?
What is the least effective way to create balance and flow in your life

What is the name of this tool and what can it be used for?
Thanks!!

Answers

That is a corqet tool it is used for fixing tires

MUST HELP FOR POINTS!!!!! HELP ME!!!!!!!!! I RLY NEED HELP ON THIS, plz give sincere answers that you truly believe are correct.Question 1 (Multiple Choice Worth 3 points)

(03.02 LC)

Integrity, positive attitude, and punctuality are considered __________ skills.
interpersonal
mathematical
personal
verbal


Question 2 (Multiple Choice Worth 3 points)

(03.02 LC)

What is the ability to pay attention to and interpret what other people are saying?
Collaboration
Decision-making
Listening
Problem-solving


Question 3 (Multiple Choice Worth 3 points)

(03.02 MC)

Devon keeps his commitments, submits work when it's due, and shows up when scheduled. What personal skill does Devon demonstrate?
Attire
Collaboration
Dependability
Verbal


Question 4 (True/False Worth 3 points)

(03.02 LC)

Curfew is an example of a workplace policy.
True
False


Question 5 (Multiple Choice Worth 3 points)

(03.02 MC)

A technology company only hires applicants who are under the age of 30. This company could face possible __________ consequences.
academic
gender
legal
technological

Answers

1.Integrity, positive attitude, and punctuality are considered _____personal_____ skills. 
2. Listening
3. 
Dependability 
4. False 
5. I am unsure of the last one but, I'm pretty sure it is academic

Decrypt the message OPEHHISTLWILKWPR which is the cyphertext produced by encrypting a plaintext message using the transposition cypher with blocks of four letters and the permutation σ of {1, 2, 3, 4} defined by A) σ(1) = 4,
B) σ(2) = 1,
C) σ(3) = 2,
D) σ(4) = 3.

Answers

Answer:

is it A ?? I'm not positive though

Explain why a single 500 kg block of granite weathers much more slowly than 100 chunks of granite weighing 5 kg each.

Answers

Weathering occurs on the surface of rocks, and lots of small rocks have a much greater surface area than one big rock.

Answer:

Weathering occurs on the surface of rocks, and lots of small rocks have a much greater surface area than one big rock.

Explanation:

Your computer will organize files into _______ order.

Answers

i belive the anser is Alphabetical.
It can be alphabetical but it can be also arranged by file size, last updated and when created. It depends what you set it to.

One part of a development team has completed an algorithm. Why is it important to share it with others on the team? Choose all that apply. If it is easy to understand, no one will dispute what is included in the algorithm. It will give everyone else an opportunity to comment on the process described in the algorithm. It will serve as the starting point for all future activity. It communicates the consecutive instructions of the solution.

Answers

Answer: B,C,D

Explanation:

Answer:

the answer is B,C,D

Explanation: