Question:
Possible 4 digit combinations?
anonymous
2014-07-04 15:31:18 UTC
Auntie has moved into a house with an outside safe that we don't know the combination to. We know that numbers cannot be duplicated in the same code (eg, 1123) and duplicate codes are not necessary (ie - if you have the code 1234, you do not need another code with the same 4 digits in, like 2314). Every time I try to come up with a list I end up duplicating codes accidentally! Any help would be appreciated.
Four answers:
?
2014-07-04 15:37:16 UTC
Well,

are there 9 or 10 digits (is 0 a authorized digit?)

anyway :

a "solution" (duplicate codes are not necessary) is a subset of 4 digits in

- either : {0, 1, 2, ... ; 9} so 10C4 = 10*9*8*7/4! = 210

- or with 9 digits, in {1, 2, ... ; 9} so 9C4 = 9*8*7*6/4! = 126

finally :



10 digits : 210

9 digits : 126



hope it' ll help !!
Samwise
2014-07-05 12:24:47 UTC
This is why computer programming was invented--so we could generate the list without duplicates.



Here is my program output, arranged in 21 rows of 10 codes so you can readily verify it has the right number of entries.



0123 0124 0125 0126 0127 0128 0129 0134 0135 0136

0137 0138 0139 0145 0146 0147 0148 0149 0156 0157

0158 0159 0167 0168 0169 0178 0179 0189 0234 0235

0236 0237 0238 0239 0245 0246 0247 0248 0249 0256

0257 0258 0259 0267 0268 0269 0278 0279 0289 0345

0346 0347 0348 0349 0356 0357 0358 0359 0367 0368

0369 0378 0379 0389 0456 0457 0458 0459 0467 0468

0469 0478 0479 0489 0567 0568 0569 0578 0579 0589

0678 0679 0689 0789 1234 1235 1236 1237 1238 1239

1245 1246 1247 1248 1249 1256 1257 1258 1259 1267

1268 1269 1278 1279 1289 1345 1346 1347 1348 1349

1356 1357 1358 1359 1367 1368 1369 1378 1379 1389

1456 1457 1458 1459 1467 1468 1469 1478 1479 1489

1567 1568 1569 1578 1579 1589 1678 1679 1689 1789

2345 2346 2347 2348 2349 2356 2357 2358 2359 2367

2368 2369 2378 2379 2389 2456 2457 2458 2459 2467

2468 2469 2478 2479 2489 2567 2568 2569 2578 2579

2589 2678 2679 2689 2789 3456 3457 3458 3459 3467

3468 3469 3478 3479 3489 3567 3568 3569 3578 3579

3589 3678 3679 3689 3789 4567 4568 4569 4578 4579

4589 4678 4679 4689 4789 5678 5679 5689 5789 6789





In case you're interested, I cranked out the program in Perl, which is currently my preferred language for quick-and-dirty programs. Here it is (with strings of periods added to force indentations in front of lines, because otherwise Answers will eat the spacing).





use strict;



my ($i, $j, $k, $l);

my $kt;



for ($i=0; $i<7; $i++) {

. for ($j=$i+1; $j<8; $j++) {

. . for ($k=$j+1; $k<9; $k++) {

. . . for ($l=$k+1; $l<10; $l++) {

. . . . $kt++;

. . . . if ($kt % 10) {print "$i$j$k$l ";}

. . . . else {print "$i$j$k$l\n";}

. . . } # $l loop

. . } # $k loop

. } # $j loop

} # $i loop
SV
2014-07-04 15:40:04 UTC
Let's take the two constraints separately.



Firstly, no duplicated digits (e.g. not 1123). How many combinations does that allow?



For the first digit you have 10 choices (assuming the digits range 0-9).

Then for the second digit you have 9 choices (one has been taken by the first digit).

Similarly the third digit has 8 choices, the fourth has 7 choices.



So that first constraint allows you 10x9x8x7 combinations.





Then we apply the second constraint, that any reordering of the code constitutes a duplicate code which is to be ignored. How does that cut down the number?



Well any given code, abcd, can be written in 4x3x2x1 ways (using the same argument as before).





So the total number of valid safe codes is (10 x 9 x 8 x 7) / (4 x 3 x 2)





By the way, if you do get into Auntie's safe I think my help is probably worth a 10% cut ;-)
Bullwinkle
2014-07-04 15:38:44 UTC
Assuming you can use ten digits [0 - 9], then there are...



10 C 4 combinations...



10 C 4 = [10 * 9 * 8 * 7] / [4 * 3 * 2] = 210 combinations



Work carefully. Don't make accidental duplications !!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...