{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import random\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[4, 9, 1, 6]\n", "Intento nro 1: 5782 toro 0 vaca 0. Vuelva a intentar\n", "Intento nro 2: 6194 toro 0 vaca 4. Vuelva a intentar\n", "Intento nro 3: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 4: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 5: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 6: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 7: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 8: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 9: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 10: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 11: 1234 toro 0 vaca 2. Vuelva a intentar\n", "Intento nro 12: 1234 toro 0 vaca 2. Vuelva a intentar\n" ] } ], "source": [ "correct_index = np.ones(10,np.int8)*-1\n", "sequences = random.sample(range(10), 4)\n", "if sequences[0]==0:\n", " sequences[0],sequences[1]=sequences[1],sequences[0]\n", "for s,k in zip(sequences,range(4)):\n", " correct_index[s] = k\n", "\n", "oportunidades = 12\n", "print(sequences)\n", "def validar_input():\n", " bad = True\n", " while bad:\n", " guess = str(input(\"Introduzca un numero.\"))\n", " if not guess.isnumeric():\n", " print(\"Debe ser una secuencia de numeros\")\n", " continue\n", " if len(guess)!=4:\n", " print(\"Numero debe ser de 4 digitos\")\n", " continue\n", " \n", " input_index = np.ones(10,np.int8)*-1\n", " for n,k in zip(guess,range(4)):\n", " if input_index[int(n)] != -1:\n", " print(\"No debe haber numeros repetidos en la secuencia\")\n", " break\n", " input_index[int(n)] = k\n", " else:\n", " bad = False\n", " return guess\n", "\n", "for i in range(oportunidades):\n", " guess = validar_input()\n", " toro = 0\n", " vaca = 0\n", " for n,k in zip(guess,range(4)):\n", " if correct_index[int(n)]==k:\n", " toro+=1\n", " elif correct_index[int(n)]!=-1:\n", " vaca+=1\n", " if toro==4:\n", " print(\"Jugador acerto el nro\")\n", " break\n", " print(f'Intento nro {i+1}: {guess} toro {toro} vaca {vaca}. Vuelva a intentar')\n", "\n", "\n" ] } ], "metadata": { "interpreter": { "hash": "7b4b4feff2f24a0f0a34464dbe537a36fda679851528fb8735cb41fa49dffb2d" }, "kernelspec": { "display_name": "Python 3.8.3 64-bit ('base': conda)", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }