+ Reply to Thread
Results 1 to 7 of 7

How to find all of the possible combinations of a four digit code

  1. #1
    Registered User
    Join Date
    02-19-2021
    Location
    United States of America
    MS-Off Ver
    365
    Posts
    2

    How to find all of the possible combinations of a four digit code

    Titles are hard
    So I'm trying to generate a list of all of the possible codes for a lockbox. The codes are four digits (0-9), each digit can only be used once (eg. things like 11 or 2342 are no good). Lastly, and most importantly, the order of the numbers doesn't matter. So 1234, 4321, 2143 are all the same code! This last part is what is stumping me the most! Any help would be greatly appreciated, thanks~

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,942

    Re: How to find all of the possible combinations of a four digit code

    Try this code - the key is that it cannot create duplicated digits, and the digits are in ascending order:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    02-19-2021
    Location
    United States of America
    MS-Off Ver
    365
    Posts
    2

    Re: How to find all of the possible combinations of a four digit code

    I think I might be doing it wrong, I can't get excel to run the macro

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,942

    Re: How to find all of the possible combinations of a four digit code


  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: How to find all of the possible combinations of a four digit code

    Here is a formula solution.

    I borrowed heavily from a solution to a similar problem José Augusto solved here: https://www.excelforum.com/excel-for...n-results.html

    The problem (sum of values) is different than yours but the issue of unique combinations is identical.
    The approach is to first identify all combinations of 4 digits by unique positions.

    Use G1:P1 to store all digits for reference.
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    1
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9


    Continued in next post. Forum won't let me edit this one.
    Last edited by FlameRetired; 02-22-2021 at 08:23 PM.
    Dave

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: How to find all of the possible combinations of a four digit code

    In D1 of the attached find
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    This returns the number of unique combinations of 4 of 10 digits. In E1 this formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    validates the count yielded by this solution.

    Define unique combinations using binary values where each of the digits is expected. IE 1s where the digits are desired and 0s where not. This is done by first determining the smallest decimal value defined by the binary value 1111000000 (unique combination of G1:P1 "0123") and the largest decimal value defined by the binary value 0000001111 (unique combination of G1:P1 "6789"). Those formulas are in B1 and C1
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    respectively.

    You will need to test all values from 15 to 960 (all 946 numbers) to find those 210 the COMBIN formula indicates. See A2:A947.

    In B2:B947 determine which of those decimal numbers' binary equivalent consists of 4 1s only. This formula does that. It is the basis of José's solution (compacted somewhat).
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In G2:P947 this "translates" those unique combinations of 4 1s to the corresponding digits in G1:P1
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    In Q2:Q947 this concatenates those digits into their unique combinations ... all 210 of them.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Let me know if you have any questions.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to find all of the possible combinations of a four digit code

    Hi November and welcome to the forum,

    I agree with FlameRetired above. There are 210 possible answers. See the attached where the first 4 columns are all possible 0-9 four digit combinations. In the next columns are those numbers sorted from small to large. Third I did an advanced filter of the second table and only show unique combinations. I used some VBA to build the first and second columns.
    Possible Lock Combos.xlsm

    BTW - I have one of those locks where you push in the buttons to get the combo. My combo is 6897 which is really 6789 as the order doesn't matter. I remember the easy one and give out the harder to remember combo.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. 24 combinations for any 4 digit number
    By Ramya Sujesh in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 12-12-2020, 11:06 AM
  2. Replies: 1
    Last Post: 05-25-2017, 02:09 AM
  3. 6-digit combinations of numbers column A
    By Stoney1 in forum Excel General
    Replies: 2
    Last Post: 06-13-2015, 07:38 AM
  4. [SOLVED] LOTTERY FILTER#4, Find if 1 Digit Sum of 2 Digit or 3 Digit, Single Cell w/ dash
    By david gonzalez in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-08-2014, 12:57 AM
  5. Finding Combinations of a Three digit Number
    By darrylx in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 11-08-2011, 05:29 AM
  6. 5 digit number combinations
    By Puppiie in forum Excel - New Users/Basics
    Replies: 14
    Last Post: 09-02-2010, 05:02 PM
  7. Implementation of VBA code to find multiple matching combinations
    By holmerz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-20-2009, 02:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1