Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get number of possible 4 digit numbers with constraints on possible digits and position of digits
    primarykey
    data
    text
    <p>I was trying to solve a programming problem and got stuck because I couldn't understand one of the examples which goes as follows, </p> <p>We guess a four digit number and the guess is "1234" . The hints given for this guess are, </p> <ol> <li><p>Each of the digits is not in it's right place (as per correct answer). That is , 1 is not in position 1, 2 is not in position 2, 3 is not in position 3 and 4 is not in position 4. </p></li> <li><p>The 4 digit correct answer contains the digits 1,2,3,4. </p></li> </ol> <p>The example gave the number of possible combinations of four digit numbers based on above constraints to be 9. {2143,2341,2413,3142,3412,3421,4123,4312,4321}</p> <p>I tried to approach the problem this way:</p> <p>approach1 :</p> <p>(Total # of combinations which is 4!) - (( Combinations which start with 1 in position 1 + Combinations with 2 in position 2 + Combinations with 3 in position 3 + Combinations with 4 in position 4)) but Couldn't get to a solution for second part of the above formula.. as Combinations which start with 1 in position 1 will be 3!- (combination which start with 2 in position 2).. and so on and I wasn't able to proceed on writing the number of combinations).</p> <p>approach2:</p> <p>(1 can be in 3 positions) * (2 can be in 3 or 2 positions based on where 1 is placed) * (3 can be in 1 or 2 positions based on where 2 is place)*(1 position for 4) -- Again not clear on how to find the # of positions for 2,3,4.</p> <p>Please help me understand how to approach this problem</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload