Skip to content

Instantly share code, notes, and snippets.

@hipdev
Created March 24, 2024 16:12
Show Gist options
  • Select an option

  • Save hipdev/4767166a3e3b5d486187ae03ba3adc90 to your computer and use it in GitHub Desktop.

Select an option

Save hipdev/4767166a3e3b5d486187ae03ba3adc90 to your computer and use it in GitHub Desktop.

Revisions

  1. hipdev created this gist Mar 24, 2024.
    30 changes: 30 additions & 0 deletions .py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    import random

    def generar_numero_secreto():
    while True:
    numero_secreto = random.randint(100, 999) # Asegura un número de tres dígitos.
    s = str(numero_secreto)
    if s[0] != s[1] and s[1] != s[2] and s[0] != s[2]: # Verifica dígitos diferentes.
    return numero_secreto

    def evaluar_intento(intento, secreto):
    intento_s = str(intento)
    secreto_s = str(secreto)

    pin = sum(intento_s[i] == secreto_s[i] for i in range(3))
    pon = sum(intento_s[i] in secreto_s and intento_s[i] != secreto_s[i] for i in range(3))

    return pin, pon

    # Generamos el número secreto (esto normalmente estaría oculto al jugador).
    numero_secreto = generar_numero_secreto()
    print(f"DEBUG: Número secreto generado: {numero_secreto}") # Esta línea es solo para propósitos de demostración.

    # Simulamos un intento del jugador.
    intento_jugador = int(input("Intenta adivinar el número de 3 dígitos con dígitos diferentes: "))

    # Evaluamos el intento.
    pin, pon = evaluar_intento(intento_jugador, numero_secreto)
    print(f"Resultado: {pin} PIN(s), {pon} PON(s)")

    # Aquí terminaría un intento. En un programa completo, se debería repetir este proceso respetando el máximo de intentos permitidos.