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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question

Please answer in matlab code.

Pincode
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.
Ex:
> pincode = [2,9,9,5,5,3];
[ repPos, pinCodeFix ] = pinCodeCheck( pinCode )
produces
repPos =
pincodeFix =
2
9
5
3
Function e
A Save
C Reset
I MATLAB Documentation
1 function [ repPos, pinCodeFix ]
pincodecheck( pincode )
=
2
3
% Your solution goes here
4
5 end
Code to call your function e
C Reset
1 pincode
2 [ repPos, pinCodeFix ] = pinCodeCheck( pinCode )
[2,9,9,5,5,3];
%3D
Transcribed Image Text:Pincode 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. Ex: > pincode = [2,9,9,5,5,3]; [ repPos, pinCodeFix ] = pinCodeCheck( pinCode ) produces repPos = pincodeFix = 2 9 5 3 Function e A Save C Reset I MATLAB Documentation 1 function [ repPos, pinCodeFix ] pincodecheck( pincode ) = 2 3 % Your solution goes here 4 5 end Code to call your function e C Reset 1 pincode 2 [ repPos, pinCodeFix ] = pinCodeCheck( pinCode ) [2,9,9,5,5,3]; %3D
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,