Thursday, 28 oct 2010 11:18 
	                    
[#] 
        gabyteodor
Module Module1
'Visual Basic + Linq
    Sub Main()
        Dim sum As Integer = 3000
        Dim x1 As Integer = 1000
        Dim x2 As Integer = 1000
        Dim x3 As Integer = 1000
        For Each prime1 In Primes()
            For Each prime2 In Primes()
                For Each prime3 In Primes()
                    If prime1 <> prime2 AndAlso prime1 <> prime3 AndAlso prime2 <> prime3 Then
                        If Distinct(prime1, prime2) AndAlso Distinct(prime2, prime3) AndAlso Distinct(prime1, prime3) Then
                            If (prime1 + prime2 + prime3) < (x1 + x2 + x3) Then
                                x1 = prime1
                                x2 = prime2
                                x3 = prime3
                            End If
                        End If
                    End If
                Next
            Next
        Next
        Console.WriteLine(x1)
        Console.WriteLine(x2)
        Console.WriteLine(x3)
        Console.WriteLine(x1 + x2 + x3)
        Console.ReadLine()
    End Sub
    Function IsPrime(ByVal p As Integer) As Boolean
        If p Mod 2 = 0 Then Return False
        For j As Integer = 3 To Math.Floor(Math.Sqrt(p)) Step 2
            If p Mod j = 0 Then Return False
        Next
        Return True
    End Function
    Function Primes() As List(Of Integer)
        Primes = New List(Of Integer)
        For i = 111 To 997 Step 2
            If Digits(i).Distinct.Count = 3 AndAlso Not Digits(i).Contains(0) AndAlso IsPrime(i) Then
                Primes.Add(i)
            End If
        Next
    End Function
    Function Distinct(ByVal p As Integer, ByVal q As Integer)
        Return Digits(p).Intersect(Digits(q)).Count = 0
    End Function
    Function Digits(ByVal p As Integer) As List(Of Integer)
        Dim x = p
        Digits = New List(Of Integer)
        While x > 0
            Digits.Add(x Mod 10)
            x = x \ 10
        End While