VBA:: Searching with System.Collections.ArrayList

* 링크 못 찾음

Thus, I was thinking that there should be a fast way to calculate the first few numbers with System.Collections.ArrayList as far as I have written about a helper to sort arrays and range sorter. So, as far as it can be obviously solved with a N^2 complexity algorithm it is quite easy to be done:

 
Public Sub TaxiCabNumber()
    
    Dim a           As Long
    Dim b           As Long
    Dim lastNumber  As Long
    Dim cnt         As Long
    
    lastNumber = 200
    
    Dim arrList     As Object
    Set arrList = CreateObject("System.Collections.ArrayList")

    For a = 1 To lastNumber
        For b = a + 1 To lastNumber            
            Dim current As String
            current = a ^ 3 + b ^ 3            
            'Debug.Assert (a <> 1 Or b <> 12) And (a <> 9 Or b <> 10)            
            If arrList.contains(current) Then
                Debug.Print current
            Else
                arrList.Add (current)
            End If            
            cnt = cnt + 1
        Next b
    Next a    
End Sub

 

 

 

 

 

 

반응형