How to count the total of all pairs permutations in an array with VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Sub Main(ByVal args As String())
        Dim arr1 As Integer() = New Integer() {1, 8, 5}
		
		' The pairs are: (1, 8), (1, 5), (8, 1), (8, 5), (5, 1), (5, 8) 
        
		Dim total_pairs As Integer = arr1.Length * (arr1.Length - 1)
        Console.WriteLine("Total Pairs = " & total_pairs)
		
        Dim arr2 As Integer() = New Integer() {1, 8, 5, 2}
		
		' The pairs are: (1, 8), (1, 5), (1, 2), (8, 1), (8, 5), (8, 2), 
		'                (5, 1), (5, 8), (5, 2), (2, 1), (2, 8), (2, 5)
        
		total_pairs = arr2.Length * (arr2.Length - 1)
        Console.WriteLine("Total Pairs = " & total_pairs)
    End Sub
End Class
 
   
   
' run:
'
' Total Pairs = 6
' Total Pairs = 12
'

 



answered Jun 16, 2024 by avibootz
...