desafio1.ipynb 3.34 KB
Newer Older
Joel Florentin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
{
 "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
}