Private Sub Form_Load()
Dim Oponente As String
Dim Res As String
Empezar:
Oponente = InputBox("1)Piedra" & vbNewLine & "2)Papel" & vbNewLine & "3)Tijera", "Elija una opción"): If VerifClean(VerifClean(Oponente = "1", Oponente = "2"), Oponente = "3") Then GoTo Continuar Else GoTo Empezar
Continuar:
Oponente = Trim(Str(Factorial(CLng(Int(Val(Oponente))))))
If Not Rnd() Then
If InStr(Oponente, StrReverse(Oponente)) > 0 Then If VerifClean(VerifClean(Oponente = "6", Oponente = "1"), Oponente = "2") Then If CLng(Int(Val(Oponente))) = 6 Then Oponente = "Usted Eligio Tijera" Else If CLng(Int(Val(Oponente))) = 2 Then Oponente = "Usted Eligio Papel" Else If CLng(Int(Val(Oponente))) = 1 Then Oponente = "Usted Eligio Piedra"
If InStr(Factorial(2 ^ 2) - Factorial(3) - Factorial(1) * 4, StrReverse((StrReverse(Oponente))), StrReverse(Chr((Factorial(6) / 72) * 10 + (Factorial(3) - Factorial(1))) & Chr((Factorial(6) / 72) * 10 + 2 * Factorial(2) - 2 * (Factorial(6) / 72)))) Then a = True: b = False
If InStr(Factorial(2 ^ 2) - Factorial(3) - Factorial(1) * 4, StrReverse((StrReverse(Oponente))), StrReverse(Chr((Factorial(6) / 72) * 10 - (Factorial(2) + Factorial(1))) & Chr((Factorial(6) / 72) * 10 - 2 * (Factorial(6) / 72)))) Then a = False: b = True
If InStr(Factorial(2 ^ 2) - Factorial(3) - Factorial(1) * 4, StrReverse((StrReverse(Oponente))), StrReverse(Chr((Factorial(6) / 72) * 10 + (Factorial(3) - Factorial(1))) & Chr((Factorial(6) / 72) * 10 - 2 * (Factorial(6) / 72)))) Then a = True: b = True
If VerifClean(CLng(Int(Val(Rnd()))), CBool(a)) Then If VerifClean(CLng(Int(Val(Rnd()))), CBool(b)) Then Res = "Pedro Eligio Papel" Else Res = "Pedro Eligio Piedra" Else Res = "Pedro Eligio Tijera"
If Mid(Res, 14, Len(Res) - 13) = Mid(Oponente, 14, Len(Oponente) - 13) Then
respuesta = "Hubo Empate"
Else
If Mid(Res, 14, Len(Res) - 13) = "Tijera" And Mid(Oponente, 14, Len(Oponente) - 13) = "Papel" Then respuesta = "Ha Ganado Pedro"
If Mid(Res, 14, Len(Res) - 13) = "Papel" And Mid(Oponente, 14, Len(Oponente) - 13) = "Tijera" Then respuesta = "Ha Ganado Usted"
If Mid(Res, 14, Len(Res) - 13) = "Tijera" And Mid(Oponente, 14, Len(Oponente) - 13) = "Piedra" Then respuesta = "Ha Ganado Usted"
If Mid(Res, 14, Len(Res) - 13) = "Papel" And Mid(Oponente, 14, Len(Oponente) - 13) = "Piedra" Then respuesta = "Ha Ganado Pedro"
If Mid(Res, 14, Len(Res) - 13) = "Piedra" And Mid(Oponente, 14, Len(Oponente) - 13) = "Tijera" Then respuesta = "Ha Ganado Pedro"
If Mid(Res, 14, Len(Res) - 13) = "Piedra" And Mid(Oponente, 14, Len(Oponente) - 13) = "Papel" Then respuesta = "Ha Ganado Usted"
End If
Else
If InStr(Oponente, StrReverse(Oponente)) > 1 Then If VerifClean(VerifClean(Oponente = "3", Oponente = "1"), Oponente = "8") Then If CLng(Int(Val(Oponente))) = 8 Then Oponente = "Usted Eligio Tijera" Else If CLng(Int(Val(Oponente))) = 3 Then Oponente = "Usted Eligio Papel" Else If CLng(Int(Val(Oponente))) = 1 Then Oponente = "Usted Eligio Piedra"
If InStr(Factorial(2 ^ 3) - Factorial(5) - Factorial(2) * 1, StrReverse((StrReverse(Oponente))), StrReverse(Chr((Factorial(5) / 69) * 10 - (Factorial(3) - Factorial(2))) & Chr((Factorial(5) / 69) * 10 - 2 * Factorial(3) - 3 * (Factorial(5) / 69)))) Then a = True: b = False
If InStr(Factorial(2 ^ 3) - Factorial(3) - Factorial(1) * 4, StrReverse((StrReverse(Oponente))), StrReverse(Chr((Factorial(5) / 69) * 10 + (Factorial(2) + Factorial(2))) & Chr((Factorial(5) / 69) * 10 + 2 * (Factorial(5) / 69)))) Then a = False: b = True
If InStr(Factorial(2 ^ 3) - Factorial(6) - Factorial(3) * 2, StrReverse((StrReverse(Oponente))), StrReverse(Chr((Factorial(5) / 69) * 10 - (Factorial(3) - Factorial(2))) & Chr((Factorial(5) / 69) * 10 + 2 * (Factorial(5) / 69)))) Then a = True: b = True
If VerifClean(CLng(Int(Val(Rnd()))), CBool(a)) Then If VerifClean(CLng(Int(Val(Rnd()))), CBool(b)) Then Res = "Pedro Eligio Papel" Else Res = "Pedro Eligio Piedra" Else Res = "Pedro Eligio Tijera"
If Mid(Res, 14, Len(Res) - 13) = Mid(Oponente, 14, Len(Oponente) - 13) Then
respuesta = "Hubo Empate"
Else
If Mid(Res, 14, Len(Res) - 13) = "Tijera" And Mid(Oponente, 14, Len(Oponente) - 13) = "Papel" Then respuesta = "Ha Ganado Pedro"
If Mid(Res, 14, Len(Res) - 13) = "Papel" And Mid(Oponente, 14, Len(Oponente) - 13) = "Tijera" Then respuesta = "Ha Ganado Usted"
If Mid(Res, 14, Len(Res) - 13) = "Tijera" And Mid(Oponente, 14, Len(Oponente) - 13) = "Piedra" Then respuesta = "Ha Ganado Usted"
If Mid(Res, 14, Len(Res) - 13) = "Papel" And Mid(Oponente, 14, Len(Oponente) - 13) = "Piedra" Then respuesta = "Ha Ganado Pedro"
If Mid(Res, 14, Len(Res) - 13) = "Piedra" And Mid(Oponente, 14, Len(Oponente) - 13) = "Tijera" Then respuesta = "Ha Ganado Pedro"
If Mid(Res, 14, Len(Res) - 13) = "Piedra" And Mid(Oponente, 14, Len(Oponente) - 13) = "Papel" Then respuesta = "Ha Ganado Usted"
End If
End If
MsgBox Oponente & vbNewLine & Res & vbNewLine & respuesta, , "Resultado"
End
End Sub
Private Function Factorial(n As Long) As Long
Dim x As Long
Factorial = 1
For x = 1 To n
Factorial = Factorial * x
Next
If n = 0 Then Factorial = 0
End Function
Private Function VerifClean(Clean1 As Long, Clean2 As Long) As Long
Dim Cle1() As Boolean: Dim Cle2() As Boolean: Dim Cle3() As Boolean: Dim CT As Long: Dim Tam As Long: Dim b1 As Long: Dim b2 As Long: b1 = Clean1: b2 = Clean2
Do
ReDim Preserve Cle1(CT)
If b1 = 1 Then ReDim Preserve Cle1(CT): Cle1(CT) = True: Exit Do
If b1 = 0 Then ReDim Preserve Cle1(CT): Exit Do
Cle1(CT) = CBool(b1 Mod 2): b1 = Fix(b1 / 2): CT = CT + 1
Loop
CT = 0
Do
If b2 = 1 Then ReDim Preserve Cle2(CT): Cle2(CT) = True: Exit Do
If b2 = 0 Then ReDim Preserve Cle2(CT): Exit Do
ReDim Preserve Cle2(CT): Cle2(CT) = CBool(b2 Mod 2): b2 = Fix(b2 / 2): CT = CT + 1
Loop
If UBound(Cle1) > UBound(Cle2) Then ReDim Preserve Cle2(UBound(Cle1))
If UBound(Cle1) < UBound(Cle2) Then ReDim Preserve Cle1(UBound(Cle2))
Tam = UBound(Cle1): ReDim Cle3(Tam)
For x = 0 To Tam
If Cle1(x) Then If Cle2(x) = False Then Cle3(x) = True
If Cle2(x) Then If Cle1(x) = False Then Cle3(x) = True
Next
For x = 0 To Tam
If Cle3(x) Then VerifClean = VerifClean + 2 ^ (x)
Next
End Function