From 81c168cfdd0a3a471e602a105203adb38315993e Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 20 Oct 2021 10:08:17 -0300 Subject: [PATCH] Dia 001 --- ForLoop.java | 27 +++++++++++++++++++++++++++ PrimerPrograma.java | 8 ++++++++ vacatoro/desafio1.ipynb | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vacatoro/readme.md | 5 +++++ vacatoro/requirements.txt | 1 + vacatoro/vacatoro.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 ForLoop.java create mode 100644 PrimerPrograma.java create mode 100644 vacatoro/desafio1.ipynb create mode 100644 vacatoro/readme.md create mode 100644 vacatoro/requirements.txt create mode 100644 vacatoro/vacatoro.py diff --git a/ForLoop.java b/ForLoop.java new file mode 100644 index 0000000..6b2c901 --- /dev/null +++ b/ForLoop.java @@ -0,0 +1,27 @@ +class ForLoop{ + public static void main(String[] args) { + int twoD[][] = new int[4][5]; + int i, j, k = 0; + for(i=0;i<4;i++){ + for(j=0;j<5;j++){ + twoD[i][j] = k; + k++; + } + } + for(i=0;i<4;i++){ + for(j=0;j<5;j++){ + System.out.print(twoD[i][j] + "\t"); + } + System.out.println(); + } + if(i>0){ + int z = 0; + } + aux(); + h=5; + } + + static void aux(){ + int h=3; + } +} \ No newline at end of file diff --git a/PrimerPrograma.java b/PrimerPrograma.java new file mode 100644 index 0000000..d2a23b3 --- /dev/null +++ b/PrimerPrograma.java @@ -0,0 +1,8 @@ +public class PrimerPrograma { + public static void main(String[] args) { + var cons = System.console(); + String nombre = cons.readLine("Introduzca su nombre: "); + String color = cons.readLine("Introduzca su color: "); + System.out.printf("%s es una persona amable que siempre esta dispuesta a ayudar a los demas. Su color favorito es %s, excelente color\n",nombre,color); + } +} diff --git a/vacatoro/desafio1.ipynb b/vacatoro/desafio1.ipynb new file mode 100644 index 0000000..1717200 --- /dev/null +++ b/vacatoro/desafio1.ipynb @@ -0,0 +1,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 +} diff --git a/vacatoro/readme.md b/vacatoro/readme.md new file mode 100644 index 0000000..be917d4 --- /dev/null +++ b/vacatoro/readme.md @@ -0,0 +1,5 @@ +Se debe contar con la libreria numpy para poder correr el programa + +Para instalar numpy: `pip install numpy` + +Para correr el script: `python vacatoro.py` \ No newline at end of file diff --git a/vacatoro/requirements.txt b/vacatoro/requirements.txt new file mode 100644 index 0000000..296d654 --- /dev/null +++ b/vacatoro/requirements.txt @@ -0,0 +1 @@ +numpy \ No newline at end of file diff --git a/vacatoro/vacatoro.py b/vacatoro/vacatoro.py new file mode 100644 index 0000000..c11b961 --- /dev/null +++ b/vacatoro/vacatoro.py @@ -0,0 +1,67 @@ + +import random +import numpy as np +correct_index = np.ones(10,np.int8)*-1 +input_index = np.zeros(10,np.int8) +sequences = random.sample(range(10), 4) # tomar una muestra de 4 elementos del 0 al 9 +oportunidades = 12 + +#intercambiar posicion en caso que el primer digito salio 0 +if sequences[0] == 0: + sequences[0],sequences[1]=sequences[1],sequences[0] + +#este array nos servira para indexar rapidamente los digitos del numerito, asi no sera necesario iterar +for s,k in zip(sequences,range(4)): + correct_index[s] = k + +#validacion de los 3 casos, que sea un numero, que tenga 4 digitos y que no se repita los digitos en la secuencia +def validar_input(): + bad = True + global input_index + + while bad: + guess = str(input("Introduzca un numero.")) + + if not guess.isnumeric(): + print("Debe ser una secuencia de numeros") + continue + + if len(guess)!=4: + print("Numero debe ser de 4 digitos") + continue + + input_index = input_index * 0 + for n,k in zip(guess,range(4)): + if input_index[int(n)] != 0: + print("No debe haber numeros repetidos en la secuencia") + break + input_index[int(n)] = k+1 + else: + bad = False + + return guess + +print(sequences)#imprimimos el valor a adivinar, a modo de facilitar testeo + +for i in range(oportunidades): + guess = validar_input()#pide el input mientras no tenga una secuencia valida + toro = 0 + vaca = 0 + + for n,k in zip(guess,range(4)): + #un array del 0 al 9 que lo que contiene es la posicion en la que se encuentra en el numero a adivinar. + #ya que son solo 4 numeros, solo 4 elementos del array tendran un indice, los demas digitos no presentes contendran -1 + #iterando el numero del jugador b, vemos si se encuentra en la posicion que actualmente estamos + if correct_index[int(n)] == k: + toro += 1 + #y si el al menos ese numero esta presente en la secuencia a adivinar. o sea si es distinto a -1 + elif correct_index[int(n)] != -1: + vaca += 1 + if toro == 4: + print("Jugador acerto el nro") + break + + print(f'Intento nro {i+1}: {guess}. toro {toro}, vaca {vaca}. Vuelva a intentar') + + + -- libgit2 0.26.0