Results 1 to 18 of 18

Thread: [RESOLVED] Possible patters of a 4 digit number

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Resolved [RESOLVED] Possible patters of a 4 digit number

    I've tried combination and permutation calculators but perhaps because I don't know how to express what I want, I haven't gotten the answer I need. For example with a three digit number there are these patterns:
    111
    112
    211
    123

    222 is not in that list because it has the same pattern as 111 and 332 is not in the list because it has the same pattern as 112, etc.

    What would that look like for a four digit number?

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Possible patters of a 4 digit number

    Why is 211 on the list, wouldn't that be the same pattern as 100?

    Or are zeroes not allowed in the permutations.

    Also is that the full list for three digit numbers? If so, why aren't numbers like 321 included?

  3. #3

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Possible patters of a 4 digit number

    For three digit numbers maybe I should have said that the four patterns are
    All digits are the same
    The left 2 digits are the same but the 3rd digit is different
    The right 2 digits are the same but the 1st digit is different
    All the digits are different

    And zeros are allowed.

  4. #4
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Possible patters of a 4 digit number

    Okay, then I don't understand why 211 is there and not 100? The right 2 digits are the same, but the left digit is different in both.

  5. #5
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Possible patters of a 4 digit number

    Also, is the rule only that the digits are different, not how much they are different by? For example, if 100 is on the list, should 400 be on the list, or should it be omitted?

    100 is 0,-1,-1 relative difference, whereas 400 is 0,-4,-4 relative difference. But they're both XYY if the relative difference doesn't matter.

  6. #6

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Possible patters of a 4 digit number

    Sorry, my fault; I'm looking for a pattern of three numbers and I'm using 1, 2 and 3 to represent those numbers. So yes, 100 is the same pattern as 211, but so is 622, 955, 033, etcetera and I'm only interested in the pattern. My purpose is to use VBA to recognize if a four digit number has a certain pattern and do different things with the number depending on its pattern. I'm looking for help to list all the petterns using 1, 2, 3 and 4.

  7. #7
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Possible patters of a 4 digit number

    Put another way, if we follow the rules you described as I've understood them, why isn't the list for 3 digit number matches as follows:

    100 <- ABB
    101 <- ABA
    102 <- ABC
    110 <- AAB
    111 <- AAA

  8. #8

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Possible patters of a 4 digit number

    Quote Originally Posted by jpbro View Post
    Put another way, if we follow the rules you described as I've understood them, why isn't the list for 3 digit number matches as follows:

    100 <- ABB
    101 <- ABA
    102 <- ABC
    110 <- AAB
    111 <- AAA
    In those terms the patterns for a 3 digit number are:
    AAA
    AAB
    BAA
    ABC

  9. #9
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Possible patters of a 4 digit number

    Why no BBA? And I still don't understand why 211 would appear instead of 100.

  10. #10

  11. #11

  12. #12
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Possible patters of a 4 digit number

    Based on what I understood from before, BBA is the same as AAB (because the 2 left digits are the same but different from the right-most digit in both), so only one should be included. Are you sure it should now be considered different?

  13. #13
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Possible patters of a 4 digit number

    And if it's truly just checking for different ABCD patterns where ABCD and DCBA would be considered the same pattern since they are both "all different", then I think the 4 digit list would be as follows:

    1000 <-- BAAA
    1001 <-- BAAB
    1002 <-- BAAC
    1010 <-- BABA
    1011 <-- BABB
    1012 <-- BABC
    1020 <-- BACA
    1021 <-- BACB
    1022 <-- BACC
    1023 <-- BACD
    1100 <-- BBAA
    1101 <-- BBAB
    1102 <-- BBAC
    1110 <-- BBBA
    1111 <-- BBBB

  14. #14

  15. #15
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: [RESOLVED] Possible patters of a 4 digit number

    This is the VB6 code I used to generate the list (requires RC6.dll reference) in case it's of any use:

    Code:
    Sub GenNums()
       Dim lo_Dict As cSortedDictionary
       Dim lo_Collection As cCollection
       Dim lo_Num As cArrayList
       Dim lo_Nums As cArrayList
       Dim l_Num As String
       Dim l_FirstNum As Long
       Dim l_PatternChar As Long
       Dim l_Key As String
       Dim ii As Long
       Dim jj As Long
       
       Set lo_Dict = New_c.SortedDictionary
       Set lo_Collection = New_c.Collection
       
       Set lo_Num = New_c.ArrayList(vbString) '
       Set lo_Nums = New_c.ArrayList(vbLong)
       
       For ii = 1000 To 9999
          l_Num = CStr(ii)
          
          l_FirstNum = Left$(l_Num, 1)
          l_PatternChar = 65
          If Not lo_Collection.Exists(CStr(l_FirstNum)) Then lo_Collection.Add CStr(l_PatternChar), CStr(l_FirstNum)
          lo_Num.Add CStr(l_PatternChar)
          
          For jj = 2 To Len(l_Num)
             l_Key = CStr(Mid$(l_Num, jj, 1))
             If lo_Collection.Exists(l_Key) Then
                lo_Num.Add lo_Collection(l_Key)
             Else
                l_PatternChar = l_PatternChar + 1
                lo_Num.Add CStr(l_PatternChar)
                lo_Collection.Add CStr(l_PatternChar), l_Key
             End If
          Next jj
          
          l_Key = lo_Num.Join
          If Not lo_Dict.Exists(l_Key) Then
             lo_Dict.Add l_Key, ii
             lo_Nums.Add ii
          End If
          
          lo_Collection.RemoveAll
          lo_Num.RemoveAll
       Next ii
       
       lo_Nums.Sort
       
       For ii = 0 To lo_Nums.Count - 1
          Debug.Print lo_Nums(ii), "<-- " & Replace$(Replace$(Replace$(Replace$(lo_Nums(ii), "0", "A"), "1", "B"), "2", "C"), "3", "D")
       Next ii
    End Sub
    Maybe there is a better way to solve the problem, but it did the trick.

  16. #16
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: [RESOLVED] Possible patters of a 4 digit number

    Quote Originally Posted by MartinLiss View Post
    I've tried combination and permutation calculators but perhaps because I don't know how to express what I want, I haven't gotten the answer I need. For example with a three digit number there are these patterns:
    111
    112
    211
    123

    222 is not in that list because it has the same pattern as 111 and 332 is not in the list because it has the same pattern as 112, etc.

    What would that look like for a four digit number?
    Does 3 even need to appear in your pattern list?
    It seems like your pattern list should be a matter of the number of places, not the number of digits, so you aren't making a pattern out of three digits, 1,2,3 but of a length of three digit places.
    So, your base patterns should be.
    111
    112
    122 same as 211 in your list
    121 same as 123 in your list

    For 4 places, I get
    1111
    1112
    1122
    1121
    1222
    1221
    1211
    1212

    I did these by hand, but if you can confirm my patterns for 3 and 4 places match what you are looking for, then I think the pattern can be easily generated.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  17. #17

  18. #18
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: [RESOLVED] Possible patters of a 4 digit number

    No, it's a free third-party DLL that isn't included with XP. The version 6 that I used also doesn't work with XP, but version 5 does. If you're interested you can get it at vbrichclient.com

Posting Permissions

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



Click Here to Expand Forum to Full Width