1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Jlenok [28]
3 years ago
7

A pincode consists of N integers between 1 and 9. In a valid pincode, no integer is allowed to repeat consecutively. Ex: The seq

uence 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.
Computers and Technology
1 answer:
ohaa [14]3 years ago
5 0

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';

You might be interested in
What is a search engine and how is it different from a browser?
padilas [110]
A search engine is a tab where you can input keywords to find certain data in the internet. An example of a search engine would be Google or Yahoo. If you type in google "images of a turtle," it would search the entire internet for an image of a turtle then send it to you. Search engines are different than browsers because browsers are the tool to open up google aka the search engine itself, then you can proceed to search up what you want.

Please give brainliest! Thank you! :D 
6 0
4 years ago
If you witness physical bullying and want to help, what should you consider first?
SashulF [63]

Answer: C

Explanation:

5 0
3 years ago
What kinds of unstructured data or big data might the BITS corporation want to gather in the future? What kind of devices might
charle [14.2K]

Answer:

Explanation:

There many commercial documents or formats to store like image, video, photos, audio file, web page, PDF, presentations, and we can use some tools to store this commercial data, for example, excel, microsoft access, mysql, sql, mongo db, and any tool to manage, store in our data with some structures and big data.

7 0
4 years ago
What is the best Genshin impact ship? My favorite is Xiao x Lumine. Put yours bellow.
denis-greek [22]

XIAO X LUMINE AAA

Explanation:

6 0
4 years ago
Read 2 more answers
Following rules of compaction, the IPv6 address 2001:0db8:0000:0000:0000:ff00:0012:3456 could also be written as _______.
vampirchik [111]

In regards to the rules of compaction, the IPv6 address 2001:0db8:0000:0000:0000:ff00:0012:3456 could also be written as 2001:db8::ff00:12:3456.

<h3>What is IPv6?</h3>

The IPv6 address is known to be a form of Internet Layer protocol made for packet-switched internetworking and it helps to give  an end-to-end datagram movement in course of multiple IP networks.

Note that, In regards to the rules of compaction, the IPv6 address 2001:0db8:0000:0000:0000:ff00:0012:3456 could also be written as 2001:db8::ff00:12:3456.

Learn more aboutIPv6 address   from

brainly.com/question/5296366

#SPJ1

4 0
2 years ago
Other questions:
  • A ___________ is used when an extra digit is added to a coded field to make sure it the entered data is correct (like social sec
    14·1 answer
  • Write a program that has the following String variables: firstName, middleName, and lastName. Initialize these with your first,
    7·1 answer
  • _____ are independent and not associated with the marketing efforts of any particular company or brand.​
    9·1 answer
  • Describe the facility that allows multiple types of operating systems to run in a virtualized environment with varying types of
    15·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    5·1 answer
  • Match the index with the value
    14·1 answer
  • What are the main dimensions of information system and their components
    13·1 answer
  • which kind of system software tells the computer how to communicate with peripherals, such as a printer or scanner?
    7·1 answer
  • A blueprint or a "print" needs to
    9·1 answer
  • A common business practice is to include a worksheet named Documentation that contains a description of the workbook, the name o
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!