Excel/permutations

Advertisement


Question
XX
XX  
Hello Tom,I Bought a combination Dlock and set a new combination code, which I failed to set. I tried is once and it worked OK so I mixed up the wheels but forgot to reset the switch on the lock  for setting a new code, I now cannot open it.I know there are 10.000 permutations.   The lock is 4 numbers across, each with 0-9 on it.Is there a way of listing the 10,000 possible 4 digit codes or is there a link to software or a chart, that I can print out the whole list so I can just cross them off as I try the combinations (without writing out the whole chart myself which I do not think I could do before running out of patience?).  Thank you! Tony

Answer
Tony

A1: 0
B1: 0
C1: 0
D1: 0

A2: =IF(MOD(ROW(),10)=0,9,MOD(ROW(),10)-1)
B2: =IF(A2=0,IF(B1=9,0,B1+1),B1)
C2: =IF(AND(B2=0,B1=9),IF(C1=9,0,C1+1),C1)
D2: =IF(AND(C2=0,C1=9),D1+1,D1)

select A2:D2 and drag fill down to row 10000

or you can run this macro:

Sub ABC()
Dim i As Long, j As Long
Dim k As Long, l As Long
Dim ii As Long
ii = 0
For i = 0 To 9
For j = 0 To 9
  For k = 0 To 9
   For l = 0 To 9
     ii = ii + 1
     Cells(ii, "F").Value = l
     Cells(ii, "G").Value = k
     Cells(ii, "H").Value = j
     Cells(ii, "I").Value = i
Next l, k, j, i

End Sub


--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.