This code is for challenge of programing
Note: The code is made in python, in case you don't have it you can download it from => Python, the repository contains the following:
This is the main code of the challenge, follow these steps:
-
In the document
01_find_numbers.py
. This is the code requested in the test. -
The code requires two inputs per console:
- The first input is to enter a text string containing the numbers separated by commas.
- The second input is to enter the target number.
-
I know that one of the requirements was that the code be less than 20 lines, but I like to comment out the code.
I decided to go a little further and try reading numbers from an external document, since the exercise mentioned it, why not try it, follow these steps:
-
In the document
02_file_find_numbers.py
. There is the code where it reads an external document. -
There is also a file in
.txt
format, for this examplenumbers.txt
that has a list of 10 thousand random numbers (positive and negative) between 1000 and -1000. -
Additionally the code will request as input the target number.
-
In addition, the code includes a
time
function to measure the execution time and verify if it meets the requirement to execute in a time better than O(n^2).
Postsdata: I didn't understand the code for the first 15 minutes, and I decided to honestly look for help on ChatGPT, once I understood it I decided to run the code. Looking for help to optimize it with ChatGPT.
Nota: El codigo esta echo en python, en caso de no tenerlo puedes descargarlo de => Python, el repositorio contiene lo siguiente:
Este es el código principal del reto, sigue estos pasos:
-
En el documento
01_find_numbers.py
. Esta el código solicitado en la prueba. -
El código requiere dos entradas por consola:
- La primera entrada es para ingresar una cadena de texto que contiene los números separados por comas.
- La segunda entrada es para ingresar el número objetivo.
-
Se que uno de los requerimientos era que el codigo fuera en menos de 20 lineas, pero a mi me gusta comentar el codigo.
Decidi ir un poco mas alla y probar la lectura de números desde un documento externo, ya que en el ejercicio lo mencionada, porque no intentarlo, sigue estos pasos:
-
En el documento
02_file_find_numbers.py
. Esta el codigo donde lee un documento externo. -
Tambien esta un archivo en formato
.txt
, Para este ejemplonumbers.txt
que tiene una lista de 10 mil números aleatorios (positivos y negativos) entre 1000 y -1000. -
Adicional el código solicitará como entrada el número objetivo.
-
Además, el código incluye una función
time
para medir el tiempo de ejecución y verificar si cumple con el requerimiento de ejecutarse en un tiempo mejor que O(n^2).
Posdata: No entendi el codigo los primero 15 minutos, y decidi honestamente buscar ayuda en ChatGPT, una vez lo entendi decidi realizar el codigo. Buscando ayuda para optimizarlo con ChatGPT.