Function wordsOK(string1 As String, string2 As String) As boolean If Mid(string1, Len(string1), 1) = Mid(string2, 1, 1) Then Return True End If Return False End Function Function Amb(A() As String, B() As String, C() As String, D() As String) As String Dim As Integer a2, b2, c2, d2 For a2 = 0 To Ubound(A) For b2 = 0 To Ubound(B) For c2 = 0 To Ubound(C) For d2 = 0 To Ubound(D) If wordsOK(A(a2),B(b2)) And wordsOK(B(b2),C(c2)) And wordsOK(C(c2),D(d2)) Then Return A(a2) + " " + B(b2) + " " + C(c2) + " " + D(d2) End If Next d2 Next c2 Next b2 Next a2 Return "" 'Cadena vacĂ­a, por ejemplo, falla End Function Dim As String set1(2), set2(2), set3(2), set4(1) set1(0) = "the" : set1(1) = "that" : set1(2) = "a" set2(0) = "frog" : set2(1) = "elephant" : set2(2) = "thing" set3(0) = "walked" : set3(1) = "treaded" : set3(2) = "grows" set4(0) = "slowly" : set4(1) = "quickly" Dim As String text = Amb(set1(), set2(), set3(), set4()) If text <> "" Then Print !"Correct sentence would be:\n" + text Else Print "Failed to fine a correct sentence." End If Sleep