Android Question Help needed for special sort/filter algorithym

tsteward

Well-Known Member
Licensed User
Longtime User
I need help to write a routine:

A little background first.
My app is for locksmiths who make keys to vehicles.
As the door lock is easiest to remove and make a key to, the manufacturers often leave some components out se we cant get a full picture of the key. After searching a key code database I can return all the possibilities by searching for the known key cuts/bitting learnt from the door lock.

Now I need to sort the result into such an order that I can re-cut a keyblank as many times as possible thus not wasting too many keyblanks and time.
Keep in mind a #1 cut removes little material from a key, to a #4 cut that removes most material meaning that part of the key cannot be cut any further.

Here are some images from a desktop app that does what I am trying to acheive.
The trick is determing which code gives the best bitting to perform the highest amount of recutting, then determining the order of the rest.

From this example you can see it only takes 9 keyblanks if your really unlucky, to cut the entire 27 different key possibilities.
Hope this makes sense to someone!

Search database
ScreenClip1.png

Result returned
ScreenClip2.png

Desired result
ScreenClip3.png
 

Ed Brown

Active Member
Licensed User
Longtime User
Hello @tsteward

I've given it a go and have the following. It's not the same result as the one you have shown but at least the approach I've used will use up less keys. I've attached the code file as well.

I should add that I've used a pseudo kind of recursion but, it works as far as I can see.

If it's not what you're after then it might be useful as a starting point for your own crack at it. ;)

Here's the results I get:
Key 1
00801 1243331113
03447 1243331124
00001 1243331234
14571 1243332244
06313 1243332444
Key 2
10666 1243331212
13315 1243331223
18917 1243331243
12461 1243334244
Key 3
03554 1243331232
15405 1243332242
13005 1243332442
06408 1243334442
Key 4
11770 1243332112
17054 1243332132
14451 1243332134
Key 5
04259 1243332123
09726 1243332224
12641 1243332424
04489 1243334424
Key 6
02136 1243332213
10383 1243334213
02409 1243334224
Key 7
10008 1243332422
19164 1243334422
Key 8
20535 1243334222
11448 1243334242

Here is the code:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim Bittings As Map
    Dim Key As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
 
    Bittings.Initialize
    Bittings.Put("10008", "1243332422")
    Bittings.Put("19164", "1243334422")
    Bittings.Put("10383", "1243334213")
    Bittings.Put("17054", "1243332132")
    Bittings.Put("11448", "1243334242")
    Bittings.Put("14571", "1243332244")
    Bittings.Put("06313", "1243332444")
    Bittings.Put("10666", "1243331212")
    Bittings.Put("04259", "1243332123")
    Bittings.Put("14451", "1243332134")
    Bittings.Put("13315", "1243331223")
    Bittings.Put("18917", "1243331243")
    Bittings.Put("12461", "1243334244")
    Bittings.Put("03554", "1243331232")
    Bittings.Put("02409", "1243334224")
    Bittings.Put("20535", "1243334222")
    Bittings.Put("00801", "1243331113")
    Bittings.Put("03447", "1243331124")
    Bittings.Put("00001", "1243331234")
    Bittings.Put("09726", "1243332224")
    Bittings.Put("12641", "1243332424")
    Bittings.Put("04489", "1243334424")
    Bittings.Put("11770", "1243332112")
    Bittings.Put("02136", "1243332213")
    Bittings.Put("15405", "1243332242")
    Bittings.Put("13005", "1243332442")
    Bittings.Put("06408", "1243334442")
 
    BeginKeySearch
End Sub

Sub BeginKeySearch()
    Key = 0
    GetKeys
End Sub

Sub GetKeys()
    If Bittings.Size = 0 Then Return ' make sure we don't keep running in a loop
 
    Key = Key + 1
    Log("Key " & Key)
 
    ' start by finding the lowest key combo
    Dim LowestCombo As Int 
    LowestCombo = FindLowestCombo
 
    Dim Code As String = Bittings.GetKeyAt(LowestCombo)
    Dim Bitting As String = Bittings.GetValueAt(LowestCombo)
 
    Log(Code & "    " & Bitting)
    Bittings.Remove(Code)
 
    FindNextLowest(Bitting)
    GetKeys
End Sub

Sub FindLowestCombo() As Int
    ' This is the easy part as we're looking for the lowest bitting value
    ' That also has the lowest number of changes from right to left
    ' Loop through each to find the lowest
    Dim Result As Int = -1
 
    Dim Lowest As String = "9999999999" ' start with a high value first
 
    ' iterate through each bitting to find the lowest
    For ndx = 0 To Bittings.Size - 1
        Dim thisBitting As String = Bittings.GetValueAt(ndx)
        If thisBitting < Lowest Then
            Lowest = thisBitting
            Result = ndx
        End If
    Next
 
    ' We should now have the lowest bitting
    Return Result
End Sub

Sub FindNextLowest(CurrentLowest As String)
    Dim Lowest As Int = -1
    Dim LowestBitting As String = ""
 
    Dim Changes As Int = 0
    Dim PrevChanges As Int = 99                ' start with a high value
    Dim NewLowest As String = "9999999999"    ' start with a high value
 
    ' iterate through each bitting
    ' We're looking for a bitting with the fewest number of changes as possible and with the lowest value
    For ndx = 0 To Bittings.Size - 1
        Dim ThisBitting As String = Bittings.GetValueAt(ndx)
        Dim ThisChar As String
        Dim LowestChar As String
     
        Changes = 0
     
        ' starting on the right iterate through each character in the bitting comparing it to the
        ' current lowest that was passed into this function
        For pos = ThisBitting.Length - 1 To 0 Step -1
            ThisChar = ThisBitting.CharAt(pos)
            LowestChar = CurrentLowest.CharAt(pos)
         
            If ThisChar >= LowestChar Then
                If ThisChar > LowestChar Then
                    ' only count the changes/differences
                    Changes = Changes + 1
                End If
            Else
                ' ignore any bitting that is/has a lower value
                Changes = -1
                Exit
            End If
        Next
     
        If Changes > 0 And Changes <= PrevChanges Then
            If ThisBitting < NewLowest Then
                NewLowest = ThisBitting
                PrevChanges = Changes
                Lowest = ndx
            End If
        End If
    Next
 
    If Lowest = -1 Then Return
    Dim LowestBitting As String = Bittings.GetValueAt(Lowest)
    Log(Bittings.GetKeyAt(Lowest) & "    " & LowestBitting)
    Bittings.Remove(Bittings.GetKeyAt(Lowest))
    FindNextLowest(LowestBitting)
End Sub
 

Attachments

  • Bittings.zip
    2.1 KB · Views: 152
Upvote 0

sorex

Expert
Licensed User
Longtime User
I don't get it. what is the relation between table1 and the keys we see in table 2?
 
Upvote 0

Ed Brown

Active Member
Licensed User
Longtime User
Hello @sorex

For the most part I don't think it really matters as the challenge was to get the least number of keys wasted when cutting. But, you're right, there doesn't seem to be a purpose to it unless it's a code stamped on the key somewhere??? Maybe @tsteward would be kind enough to fill in that detail.
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
This is the scenario I assume, customer had lost key to car, calls locksmith who manages to open car door. Can create one or more keys that open the door by taking the lock out and looking at the physical details (or he might have a bunch of numbered keys that will open any door from this manufacturers). Can't take out the ignition lock because it is too difficult. Locksmith has access to a database that lists all the potential ignition keys that match the door lock, there could be a lot say 40. Rather than waste 40 blanks, it it better to start off with keys that contain the most metal then cuts bits out to make some of the other possibilities. Hence the problem, create lists of codes that use the fewest number of blanks to cover all the possibilities. I guess there is more than one solution in many cases, and it looks like someone on the forum has found a better algorithm then the one used in the example quoted.

I haven't been able to try this as I'm on holiday without access to the B4A compiler.
 
Last edited:
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Derek has pretty much summed it up. As Locksmiths if we remove a door lock some vehicles have a code stamped on the door. We can look up this blind code and it will give us the bitting. So the code is like the record number if you like.
With some tools now available we can decode the door lock without removing it but the door lock has less or different components than the ignition. Comoe code series may have 10,000 records. Each bitting might be 10 digits. Usually numbered between 1-4 but some can be 1-9 or more but very rare. Then the door lock may containg positions 3-10 for example and the ignition all 10 or 1-8 etc.

Ed Brown thank you thats a great start i'm off to work but will look coser at it tonight - thank you.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
ok, overhere they simply start with "blank" keys that have all the metal when cloning a key.
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
ok, overhere they simply start with "blank" keys that have all the metal when cloning a key.

Same in Australia, its just that when you have cut a trial key, you can still modify it further by selectively cutting bits out at particular places thus making another key combination that you can test in the ignition.
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Hello Ed
Thanks for a great start.
If I change the data for the following I still get goods results but not the largest lists of bittings first.
B4X:
'    database search 124*334***

Bittings.Put("40466", "1242334212")
Bittings.Put("40879", "1242334223")
Bittings.Put("40470", "1242334234")
Bittings.Put("40717", "1242334344")
Bittings.Put("40795", "1242334232")
Bittings.Put("13383", "1242334243")
Bittings.Put("40551", "1242334443")
Bittings.Put("40145", "1242334322")
Bittings.Put("40953", "1242334324")
Bittings.Put("40342", "1242334434")
Bittings.Put("10383", "1243334213")
Bittings.Put("2409", "1243334224")
Bittings.Put("12461", "1243334244")
Bittings.Put("20535", "1243334222")
Bittings.Put("11448", "1243334242")
Bittings.Put("3831", "1244334243")
Bittings.Put("18764", "1244334212")
Bittings.Put("9485", "1244334223")
Bittings.Put("9599", "1244334234")
Bittings.Put("40261", "1242334342")
Bittings.Put("6408", "1243334442")
Bittings.Put("11778", "1242334423")
Bittings.Put("4489", "1243334424")
Bittings.Put("15979", "1242334432")
Bittings.Put("3893", "1244334432")
Bittings.Put("19164", "1243334422")
Bittings.Put("7161", "1244334423")
Bittings.Put("7201", "1244334232")
Bittings.Put("13331", "1244334342")
Bittings.Put("17341", "1244334322")
Bittings.Put("12813", "1244334324")
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Hi @tsteward

Hmm... ok. Are you able to post the expected results so I/forum can use as a baseline?
Your results are correct just doesn't show the largest branches of the tree first.

I have also found another complication. As some code series have a double bitting seperated by a "-" this causes errors. IE the bittings are 123456-221134 for example.
 

Attachments

  • ScreenClip4.png
    ScreenClip4.png
    24.7 KB · Views: 172
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Here is some double bitted data to play with.
I can't think of any further complications at this time. Sorry about this one.
0K001,232131-321151
0K002,252131-321151
0K003,224131-321151
0K004,244131-321151
0K005,264131-321151
0K006,126231-321151
0K007,246231-321151
0K008,266231-321151
0K009,241331-321151
0K010,262331-321151
0K011,254331-321151
0K012,215431-321151
0K013,235431-321151
0K014,256431-321151
0K015,221531-321151
0K016,241531-321151
0K017,262531-321151
0K018,213531-321151
0K019,233531-321151
0K020,254531-321151
0K021,215631-321151
0K022,235631-321151
0K023,256631-321151
0L349,432131-321151
0L351,424131-321151
0L352,444131-321151
0L353,464131-321151
0L354,426231-321151
0L355,446231-321151
0L356,466231-321151
0L359,454331-321151
0L361,435431-321151
0L362,456431-321151
0L364,441531-321151
0L365,462531-321151
0L368,454531-321151
0L370,435631-321151
0L371,456631-321151
0M701,664131-321151
0M703,646231-321151
0M704,666231-321151
0M707,654331-321151
0M709,656431-321151
0M711,641531-321151
0M712,662531-321151
0M714,654531-321151
0M715,635631-321151
0M716,656631-321151
 
Upvote 0

Ed Brown

Active Member
Licensed User
Longtime User
Hello @tsteward

Ah I see. Ok that should be easy enough to sort out (pardon the bad pun).
When you say that is causes errors I'm assuming an RTE (Run Time Error)? I haven't tried playing with the double bitted combinations as yet and am also about to head off to work.
 
Upvote 0

Ed Brown

Active Member
Licensed User
Longtime User
Hello @tsteward

I've added the sorting for the groups of combinations. The issue with the double bitted combinations was frustrating to solve. Basically, either B4A or the Java compiler is, in my view, incorrectly treating a string as a double when the string mostly consists of numeric characters. Using methods applied by others on the forum still did not work. But, to cut a long rant short, it works now. It's just a shame that one has to use 'compareTo' with strings.

Attached is the updated code file. I've added a few more comments and tried to pretty up the output a bit.

Here's what the code looks like now:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Type CodeBittingCombo (Code As String, Bitting As String)
  
    Dim Bittings As Map            ' contains the code/bittings to be arranged
    Dim KeySets As List            ' contains the arranged code/bittings for all key sets
    Dim KeySet As Map            ' contains the arranged code/bittings for a single key set
    Dim Key As Int                ' Key number
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
  
    KeySets.Initialize
    Bittings.Initialize

'    Bittings.Put("40466",     "1242334212")
'    Bittings.Put("40879",     "1242334223")
'    Bittings.Put("40470",     "1242334234")
'    Bittings.Put("40717",     "1242334344")
'    Bittings.Put("40795",     "1242334232")
'    Bittings.Put("13383",     "1242334243")
'    Bittings.Put("40551",     "1242334443")
'    Bittings.Put("40145",     "1242334322")
'    Bittings.Put("40953",     "1242334324")
'    Bittings.Put("40342",     "1242334434")
'    Bittings.Put("10383",     "1243334213")
'    Bittings.Put("2409",     "1243334224")
'    Bittings.Put("12461",     "1243334244")
'    Bittings.Put("20535",     "1243334222")
'    Bittings.Put("11448",    "1243334242")
'    Bittings.Put("3831",     "1244334243")
'    Bittings.Put("18764",     "1244334212")
'    Bittings.Put("9485",     "1244334223")
'    Bittings.Put("9599",     "1244334234")
'    Bittings.Put("40261",     "1242334342")
'    Bittings.Put("6408",     "1243334442")
'    Bittings.Put("11778",     "1242334423")
'    Bittings.Put("4489",     "1243334424")
'    Bittings.Put("15979",     "1242334432")
'    Bittings.Put("3893",     "1244334432")
'    Bittings.Put("19164",     "1243334422")
'    Bittings.Put("7161",     "1244334423")
'    Bittings.Put("7201",     "1244334232")
'    Bittings.Put("13331",     "1244334342")
'    Bittings.Put("17341",     "1244334322")
'    Bittings.Put("12813",     "1244334324")  
  
'    Bittings.Put("10008", "1243332422")
'    Bittings.Put("19164", "1243334422")
'    Bittings.Put("10383", "1243334213")
'    Bittings.Put("17054", "1243332132")
'    Bittings.Put("11448", "1243334242")
'    Bittings.Put("14571", "1243332244")
'    Bittings.Put("06313", "1243332444")
'    Bittings.Put("10666", "1243331212")
'    Bittings.Put("04259", "1243332123")
'    Bittings.Put("14451", "1243332134")
'    Bittings.Put("13315", "1243331223")
'    Bittings.Put("18917", "1243331243")
'    Bittings.Put("12461", "1243334244")
'    Bittings.Put("03554", "1243331232")
'    Bittings.Put("02409", "1243334224")
'    Bittings.Put("20535", "1243334222")
'    Bittings.Put("00801", "1243331113")
'    Bittings.Put("03447", "1243331124")
'    Bittings.Put("00001", "1243331234")
'    Bittings.Put("09726", "1243332224")
'    Bittings.Put("12641", "1243332424")
'    Bittings.Put("04489", "1243334424")
'    Bittings.Put("11770", "1243332112")
'    Bittings.Put("02136", "1243332213")
'    Bittings.Put("15405", "1243332242")
'    Bittings.Put("13005", "1243332442")
'    Bittings.Put("06408", "1243334442")
  
    Bittings.Put("0K001", "232131-321151")
    Bittings.Put("0K002", "252131-321151")
    Bittings.Put("0K003", "224131-321151")
    Bittings.Put("0K004", "244131-321151")
    Bittings.Put("0K005", "264131-321151")
    Bittings.Put("0K006", "126231-321151")
    Bittings.Put("0K007", "246231-321151")
    Bittings.Put("0K008", "266231-321151")
    Bittings.Put("0K009", "241331-321151")
    Bittings.Put("0K010", "262331-321151")
    Bittings.Put("0K011", "254331-321151")
    Bittings.Put("0K012", "215431-321151")
    Bittings.Put("0K013", "235431-321151")
    Bittings.Put("0K014", "256431-321151")
    Bittings.Put("0K015", "221531-321151")
    Bittings.Put("0K016", "241531-321151")
    Bittings.Put("0K017", "262531-321151")
    Bittings.Put("0K018", "213531-321151")
    Bittings.Put("0K019", "233531-321151")
    Bittings.Put("0K020", "254531-321151")
    Bittings.Put("0K021", "215631-321151")
    Bittings.Put("0K022", "235631-321151")
    Bittings.Put("0K023", "256631-321151")
    Bittings.Put("0L349", "432131-321151")
    Bittings.Put("0L351", "424131-321151")
    Bittings.Put("0L352", "444131-321151")
    Bittings.Put("0L353", "464131-321151")
    Bittings.Put("0L354", "426231-321151")
    Bittings.Put("0L355", "446231-321151")
    Bittings.Put("0L356", "466231-321151")
    Bittings.Put("0L359", "454331-321151")
    Bittings.Put("0L361", "435431-321151")
    Bittings.Put("0L362", "456431-321151")
    Bittings.Put("0L364", "441531-321151")
    Bittings.Put("0L365", "462531-321151")
    Bittings.Put("0L368", "454531-321151")
    Bittings.Put("0L370", "435631-321151")
    Bittings.Put("0L371", "456631-321151")
    Bittings.Put("0M701", "664131-321151")
    Bittings.Put("0M703", "646231-321151")
    Bittings.Put("0M704", "666231-321151")
    Bittings.Put("0M707", "654331-321151")
    Bittings.Put("0M709", "656431-321151")
    Bittings.Put("0M711", "641531-321151")
    Bittings.Put("0M712", "662531-321151")
    Bittings.Put("0M714", "654531-321151")
    Bittings.Put("0M715", "635631-321151")
    Bittings.Put("0M716", "656631-321151")
   
    BeginKeySearch
End Sub

Sub BeginKeySearch()
    Key = 0
    GetKeys
  
    ' It's at this point that we should now have a bunch of keys (another bad pun) in the LIST
    ' We sort the LIST by the number of combinations in Descending order
    ' The LIST does not have a numbered KEY - we don't need one.
    Dim SortedKeySets As List
    SortedKeySets.Initialize
  
    Dim KeyNum As Int = 0
  
    Log (CRLF & "Sorted sets")
    Do While KeySets.Size > 0
        ' Find the first set that has the most keys
        Dim SetSize As Int = 0
        Dim HighestSet As Map
        Dim HighestNdx As Int = 0
        For SetNdx = 0 To KeySets.Size - 1
            Dim Set As Map = KeySets.Get(SetNdx)
            If Set.Size > SetSize Then
                SetSize     = Set.Size
                HighestSet     = Set
                HighestNdx    = SetNdx
            End If
        Next
      
        ' Display each of the combinations for the key
        KeyNum = KeyNum + 1
        Log("Key #" & KeyNum)
        For Ndx = 0 To HighestSet.Size - 1
            Dim Code    As String    = HighestSet.GetKeyAt(Ndx)
            Dim Bitting    As String    = HighestSet.GetValueAt(Ndx)
            Log(Code & "    " & Bitting)
        Next
      
        Log(CRLF & " ")    ' just for the sake of being pretty
      
        ' Now remove the set that we have just shown
        KeySets.RemoveAt(HighestNdx)
    Loop
  
End Sub

Sub GetKeys()
    If Bittings.Size = 0 Then Return ' make sure we don't keep running in a loop
  
    Key = Key + 1
    Log("Key " & Key)
  
    ' Create a new Map to contain the keys for this set of combinations
    Dim NewKeySet As Map
    NewKeySet.Initialize
  
    KeySet = NewKeySet    ' copy the reference so we can access the list
  
    ' adding the new KeySet to the LIST is also done by REFERENCE
    ' So when we add a new combination to the KeySet it will also be in the LIST
    KeySets.Add(KeySet)
  
    ' start by finding the lowest key combo
    Dim LowestCombo As Int  
    LowestCombo = FindLowestCombo
  
    Dim Code As String = Bittings.GetKeyAt(LowestCombo)
    Dim Bitting As String = Bittings.GetValueAt(LowestCombo)
  
    ' The lowest combination is always the first in the set
    KeySet.Put(Code, Bitting)
    Log(Code & "    " & Bitting) ' Show in the log as well
  
    ' Remove the code/combination from the list
    Bittings.Remove(Code)
  
    ' Go and find the next lowest key combination
    FindNextLowest(Bitting)        ' this is a recursive routine
    GetKeys                        ' call myself again until we run out of combinations
End Sub

Sub FindLowestCombo() As Int
    ' This is the easy part as we're looking for the lowest bitting value
    ' That also has the lowest number of changes from right to left
    ' Loop through each to find the lowest
  
    ' Result is used to determine if a combination was found.
    ' It is an index to the combination that is the lowest
    ' A value other than -1 means that a combination was found.
    Dim Result As Int = -1
  
    Dim Lowest As String = "ZZZZZZZZZZZZZZZZZZ"    ' start with a high value first
  
    ' iterate through each bitting to find the lowest
    For ndx = 0 To Bittings.Size - 1
        Dim thisBitting As String = Bittings.GetValueAt(ndx)
        If thisBitting.CompareTo(Lowest) < 0 Then
            Lowest = thisBitting
            Result = ndx
        End If
    Next
  
    ' We should now have the lowest bitting
    Return Result
End Sub

Sub FindNextLowest(CurrentLowest As String)
    Dim Lowest             As Int         = -1                    ' Index into Bittings map with the lowest Bitting Combination
    Dim LowestBitting     As String     = ""                    ' Lowest bitting combination found
  
    Dim Changes         As Int         = 0
    Dim PrevChanges     As Int         = 99                    ' start with a high value
    Dim NewLowest         As String     = "ZZZZZZZZZZZZZZZZZZ"    ' start with a high value
  
    ' iterate through each remaining bitting combination
    ' We're looking for a bitting with the fewest number of changes as possible and with the lowest value
    For ndx = 0 To Bittings.Size - 1
        Dim ThisBitting    As String    = Bittings.GetValueAt(ndx)
        Dim ThisChar     As String
        Dim LowestChar     As String
      
        Changes = 0
      
        ' starting on the right iterate through each character in the bitting comparing it to the
        ' current lowest that was passed into this function
        For pos = ThisBitting.Length - 1 To 0 Step -1
            ThisChar = ThisBitting.CharAt(pos)
            LowestChar = CurrentLowest.CharAt(pos)
          
            If ThisChar.CompareTo(LowestChar) >= 0 Then
                If ThisChar.CompareTo(LowestChar) > 0 Then
                    ' only count the changes/differences
                    Changes = Changes + 1
                End If
            Else
                ' ignore any bitting that is/has a lower value
                Changes = -1
                Exit
            End If
        Next
      
        If Changes > 0 And Changes <= PrevChanges Then
            If ThisBitting.CompareTo(NewLowest) < 0 Then
                NewLowest = ThisBitting
                PrevChanges = Changes
                Lowest = ndx
            End If
        End If
    Next
  
    If Lowest = -1 Then Return    ' nothing was found to be lower
  
    ' Add the next key combination to our set
    Dim LowestBitting As String = Bittings.GetValueAt(Lowest)
    Dim Code As String = Bittings.GetKeyAt(Lowest)
    KeySet.Put(Code, LowestBitting)
  
    Log(Code & "    " & LowestBitting)
    Bittings.Remove(Code)                ' remove this combination so we don't use it again
    FindNextLowest(LowestBitting)        ' recursively call myself for the next key
End Sub
 

Attachments

  • Bittings.zip
    3.5 KB · Views: 151
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Hey Ed thanks for all your work.
BUT (yeah theres always a but) no bigy is it possible to show the keys with the most bittings first as in the key that can be re-cut the most.

Current results show perhaps 4 recuts then 4 recuts then 3 recuts then 1 or 2 recuts then jumps back to 3 recuts.

Love your work

Tony
 
Upvote 0

Ed Brown

Active Member
Licensed User
Longtime User
Hello @tsteward

I've double checked and it is sorting it. However, I've left log statements in the code to show that it's doing something and these are not sorted. It sorts the list at the end when all of the combinations have been processed.

Apologies for the confusion.
 
Upvote 0
Top