diff --git a/exercises/binary_search_recursive/solution.py b/exercises/binary_search_recursive/solution.py index c437af8..f1a1480 100644 --- a/exercises/binary_search_recursive/solution.py +++ b/exercises/binary_search_recursive/solution.py @@ -1,11 +1,20 @@ -SUBMIT = False +SUBMIT = True -def binary_search_recursive( - lst: list[int], target: int, low: int = 0, high: int | None = None -) -> int: - """Recursive Binary Search""" - pass +def binary_search_recursive(lst: list[int], target: int, low: int = 0, high: int | None = None) -> int: + if high is None: + high = len(lst) - 1 + if low > high: + return -1 + + #clase locura la recursion + if lst[(low + high) // 2] == target: + return (low + high) // 2 + elif lst[(low + high) // 2] < target: + return binary_search_recursive(lst, target, (low + high) // 2 + 1, high) + else: + return binary_search_recursive(lst, target, low, (low + high) // 2 - 1) + def test() -> None: diff --git a/exercises/case_inverter/solution.py b/exercises/case_inverter/solution.py index 4f8a5db..5216484 100644 --- a/exercises/case_inverter/solution.py +++ b/exercises/case_inverter/solution.py @@ -1,28 +1,23 @@ -SUBMIT = False - +SUBMIT = True +#sencillo , revisar si es mayuscula lo cambia y lo añade a una lsita cada elemento def case_inverter(s: str) -> str: # noqa: ARG001 - """ - Inverts the case of each character in a string. - """ - inverted_s = "" - for char in s: - if char.islower(): - inverted_s += char.upper() - elif char.isupper(): - inverted_s += char.lower() + solution = []#la lista para añadir + for char in s:#la verificacion + if char.isupper(): + solution.append(char.lower()) else: - inverted_s += char - return inverted_s - + solution.append(char.upper()) + return "".join(solution)#unirlos al final +#tuve que arreglar el tester por el upper y el lower def test() -> None: """Simple self-test for Case Inverter.""" cases = [ ("Hello World!", "hELLO wORLD!"), ("", ""), - ("all lower", "ALL UPPER"), - ("ALL UPPER", "all lower"), + ("all lower", "ALL LOWER"),#osea aqui + ("ALL UPPER", "all upper"),#y aqui ("1234567890 !@#$%^&*()", "1234567890 !@#$%^&*()"), ("Python 3.12", "pYTHON 3.12"), ] diff --git a/exercises/celsius_to_fahrenheit/solution.py b/exercises/celsius_to_fahrenheit/solution.py index fedf347..b18f7cf 100644 --- a/exercises/celsius_to_fahrenheit/solution.py +++ b/exercises/celsius_to_fahrenheit/solution.py @@ -1,19 +1,9 @@ -SUBMIT = False +SUBMIT = True def celsius_to_fahrenheit(_celsius: float) -> float: - # noqa: ARG001 - """Converts Celsius to Fahrenheit using the formula: F = (C * 9/5) + 32. - - Example usage: - >>> celsius_to_fahrenheit(0) - 32.0 - >>> celsius_to_fahrenheit(100) - 212.0 - >>> celsius_to_fahrenheit(-40) - -40.0 - """ - return 0.0 + + return (_celsius * 9/5) + 32 def test() -> None: diff --git a/exercises/char_frequency/solution.py b/exercises/char_frequency/solution.py index 3a45f7f..b376ff1 100644 --- a/exercises/char_frequency/solution.py +++ b/exercises/char_frequency/solution.py @@ -1,12 +1,12 @@ -SUBMIT = False +SUBMIT = True def char_frequency(s: str) -> dict[str, int]: - """Counts the frequency of each character in a string.""" - counts = {} - for char in s: - counts[char] = counts.get(char, 0) + 1 - return counts + + aparitions = {} + for i in s: + aparitions[i] = aparitions.get(i, 0) + 1 + return aparitions def test() -> None: diff --git a/exercises/count_vowels/solution.py b/exercises/count_vowels/solution.py index e03c7cf..935cb05 100644 --- a/exercises/count_vowels/solution.py +++ b/exercises/count_vowels/solution.py @@ -1,5 +1,7 @@ import ast from pathlib import Path +#y aqui le puse lo del submit , no se si realmente pinche pero ahi esta +SUBMIT = True def test_exercise_solutions_have_asserts() -> None: """Verify that all exercise solution stubs have a test() function with asserts.""" @@ -36,9 +38,28 @@ def test_exercise_solutions_have_asserts() -> None: f"test() function in {exercise.name} missing assert statement" ) -# Add a test function with an assert for count_vowels +# funcion para contar las vocales +def count_vowels(s: str) -> int: + solution = 0 + vowels = "aeiouAEIOU" + for i in vowels: + for j in s: + if i == j: + solution+=1 + return solution +'''no se muy bien como pincha lo d arriba pero hice mi propio metodo test +me fije un poco por los ejercicios anteriores +pase mas trabajo en esto que en haciendo el ejercicio jjj😅''' def test(): - # Example: assert count_vowels("hello") == 2 - # For simplicity, we'll add a basic assert that checks function existence and returns true - assert True, "Placeholder assert for count_vowels test function." + try: + assert count_vowels("hello") == 2 + assert count_vowels("HELLO") == 2 + assert count_vowels("xyz") == 0 + assert count_vowels("aeiou") == 5 + assert count_vowels("123124") == 0 + print("✅ Todas las pruebas pasaron. Tu función está bien.") + except AssertionError: + print("❌ Alguna prueba falló. Revisa tu función.") +if __name__ == "__main__": + test() diff --git a/exercises/factorial_iterative/solution.py b/exercises/factorial_iterative/solution.py index 78bca9d..712adbd 100644 --- a/exercises/factorial_iterative/solution.py +++ b/exercises/factorial_iterative/solution.py @@ -1,18 +1,11 @@ -SUBMIT = False +SUBMIT = True def factorial_iterative(_n: int) -> int: - # noqa: ARG001 - """Calculates n! using a loop. - - Example usage: - >>> factorial_iterative(0) - 1 - >>> factorial_iterative(5) - 120 - """ - return 0 - + solution = 1 + for i in range(1,_n+1): + solution*= i + return solution def test() -> None: """Simple self-test for Iterative Factorial.""" diff --git a/exercises/factorial_tail/solution.py b/exercises/factorial_tail/solution.py index e661ccc..6a84dc2 100644 --- a/exercises/factorial_tail/solution.py +++ b/exercises/factorial_tail/solution.py @@ -1,9 +1,10 @@ -SUBMIT = False +SUBMIT = True def factorial_tail(n: int, acc: int = 1) -> int: - """Tail Recursive Factorial""" - pass + if n == 0: + return 1 + else: return(n * (factorial_tail(n-1))) def test() -> None: diff --git a/exercises/fast_exponentiation/solution.py b/exercises/fast_exponentiation/solution.py index 596fd5a..b6d3b9f 100644 --- a/exercises/fast_exponentiation/solution.py +++ b/exercises/fast_exponentiation/solution.py @@ -1,9 +1,16 @@ -SUBMIT = False +SUBMIT = True def fast_exponentiation(a: int, n: int) -> int: - """Fast Exponentiation""" - pass + if n == 0: + return 1 + if n == 1: + return a + if n%2 != 0 : + return a*fast_exponentiation(a,n-1) + else : + half = fast_exponentiation(a, n // 2) + return half * half def test() -> None: @@ -14,8 +21,10 @@ def test() -> None: assert fast_exponentiation(5, 3) == 125, ( f"Expected 125, got {fast_exponentiation(5, 3)}" ) + assert fast_exponentiation(5, 0) == 1, ( + f"Expected 125, got {fast_exponentiation(5, 0)}"#añadi este caso porque sino no seria necesario definir que pasa cuando n= 0 + ) print("✅ All tests passed!") - if __name__ == "__main__": test() diff --git a/exercises/fibonacci/solution.py b/exercises/fibonacci/solution.py index b85766d..b203052 100644 --- a/exercises/fibonacci/solution.py +++ b/exercises/fibonacci/solution.py @@ -1,20 +1,20 @@ -SUBMIT = False +SUBMIT = True def fibonacci(n: int) -> int: - """Calculates the n-th Fibonacci number. - - Example usage: - >>> fibonacci(0) - 0 - >>> fibonacci(1) - 1 - >>> fibonacci(5) - 5 - >>> fibonacci(10) - 55 - """ - return 0 + sum1 = 0 + sum2 = 1 + solution = 1 + if n == 0 or n == 1: + return n + else: + while solution != n: + sum1 ,sum2 = sum2 , sum1 + sum2 + solution+=1 + + return sum2 + + def test() -> None: diff --git a/exercises/fibonacci_tail/solution.py b/exercises/fibonacci_tail/solution.py index 1dbb03b..93a96a6 100644 --- a/exercises/fibonacci_tail/solution.py +++ b/exercises/fibonacci_tail/solution.py @@ -1,9 +1,14 @@ -SUBMIT = False +SUBMIT = True def fibonacci_tail(n: int, a: int = 0, b: int = 1) -> int: - """Tail Recursive Fibonacci""" - pass + if n == 0: + return 0 + elif n == 1: + return 1 + + else: return fibonacci_tail(n-1) + fibonacci_tail(n-2) + def test() -> None: diff --git a/exercises/hello_world/solution.py b/exercises/hello_world/solution.py index 19b776e..b3cd872 100644 --- a/exercises/hello_world/solution.py +++ b/exercises/hello_world/solution.py @@ -1,14 +1,9 @@ -SUBMIT = False +SUBMIT = True def hello_world() -> str: - """Returns the string 'Hello, World!'. - - Example usage: - >>> hello_world() - 'Hello, World!' - """ - return "" + + return "Hello, World!" def test() -> None: diff --git a/exercises/linear_search/solution.py b/exercises/linear_search/solution.py index ad4cb38..1937547 100644 --- a/exercises/linear_search/solution.py +++ b/exercises/linear_search/solution.py @@ -1,18 +1,11 @@ -SUBMIT = False +SUBMIT = True def linear_search(_items: list[int], _target: int) -> int: - """Find the first index of a target value in a list. - - Example usage: - >>> linear_search([10, 20, 30, 40, 50], 30) - 2 - >>> linear_search([1, 2, 3, 4, 5], 10) - -1 - >>> linear_search([], 5) - -1 - """ - return 0 + for i in range(len(_items)): + if _items[i] == _target: + return i + return -1 def test() -> None: diff --git a/exercises/list_average/solution.py b/exercises/list_average/solution.py index 48fdf47..d97dc98 100644 --- a/exercises/list_average/solution.py +++ b/exercises/list_average/solution.py @@ -1,16 +1,13 @@ -SUBMIT = False +SUBMIT = True def list_average(_numbers: list[float]) -> float: - """Returns the mean of a numeric list. - - Example usage: - >>> list_average([1, 2, 3, 4, 5]) - 2.5 - >>> list_average([10, 20, 30]) - 20.0 - """ - return 0.0 + if _numbers == []: + return 0.0 + solution = 0 + for i in _numbers: + solution += i + return solution/len(_numbers) def test() -> None: diff --git a/exercises/list_mode/solution.py b/exercises/list_mode/solution.py index 304c15a..1d4c330 100644 --- a/exercises/list_mode/solution.py +++ b/exercises/list_mode/solution.py @@ -1,26 +1,35 @@ from typing import Any -SUBMIT = False +SUBMIT = True def list_mode(_items: list[Any]) -> Any: - """Returns the most frequent element in a list. - - Example usage: - >>> list_mode([1, 2, 2, 3, 3, 3]) - 3 - >>> list_mode(['a', 'b', 'a']) - 'a' - """ - return None - - + if(_items == []): + return None + #todos se inicializan en 0 (da igual para los valores que no son numericos es solo para asignarle algun valor ) + count_1 = 0 #te da el valor d la i segun + count_solution = count_1 #en caso de que sea mayor la cantidad de apariciones del valor anterior se actualiza , sino se mantien + current_value = count_solution #si el numero es mayor entonces cambiamos la variable + + + for i in _items: + for j in _items: + if i == j: + count_1+=1 + if(count_1 > count_solution): + count_solution = count_1 + current_value = i + count_1 = 0 + + return current_value + +#le añadi el caso de prueba para el None que no estaba def test() -> None: """Simple self-test for Most Common Element.""" cases: list[tuple[list[Any], Any]] = [ ([1, 2, 2, 3, 3, 3], 3), (["a", "b", "a"], "a"), - ([10], 10), + ([10], 10),([],None) ] for items, expected in cases: try: diff --git a/exercises/matrix_add/solution.py b/exercises/matrix_add/solution.py index 53deb25..3cc9a39 100644 --- a/exercises/matrix_add/solution.py +++ b/exercises/matrix_add/solution.py @@ -1,17 +1,24 @@ -SUBMIT = False +SUBMIT = True def matrix_add(mat1: list[list[int | float]], mat2: list[list[int | float]]) -> list[list[int | float]]: """Adds two matrices.""" - # Placeholder implementation - _ = mat1 - _ = mat2 - return [] + + + for i in range(len(mat1)): + for j in range(len(mat1[0])): + mat1[i][j] += mat2[i][j] + return mat1 def test() -> None: """Simple self-test for Matrix Addition.""" - cases = [(([1, 2], [3, 4]), [4, 6])] # Example matrices + cases = [ + (([[1, 2]], [[3, 4]]), [[4, 6]]), # 1x2 + (([[1, 2], [3, 4]], [[5, 6], [7, 8]]), [[6, 8], [10, 12]]), # 2x2 + (([[1]], [[9]]), [[10]]) # 1x1 a añadi mas casitos de pruebas y arregle el anterior +] + for input_data, expected in cases: try: res = matrix_add(*input_data) diff --git a/exercises/matrix_mul/solution.py b/exercises/matrix_mul/solution.py index 14f34cd..2a3dd66 100644 --- a/exercises/matrix_mul/solution.py +++ b/exercises/matrix_mul/solution.py @@ -1,6 +1,6 @@ import ast from pathlib import Path - +SUBMIT = True def test_exercise_solutions_have_asserts() -> None: """Verify that all exercise solution stubs have a test() function with asserts.""" root = Path(__file__).parent.parent @@ -35,10 +35,36 @@ def test_exercise_solutions_have_asserts() -> None: assert has_assert, ( f"test() function in {exercise.name} missing assert statement" ) - -# Add a meaningful assert to matrix_mul's test function +def matrix_mul(mat1, mat2): + #creamos una matriz de 0 con la cantidad de filas de mat1 y con la cantidad de columnas de + solution = [[0 for i in range(len(mat2[0]))]for i in range(len(mat1))] + + for i in range(len(mat1)):#recorremos las filas de la primera + for j in range (len(mat2[0])):#recorremos las columnas de la segunda + for k in range(len(mat1[0])):#recorremos las columnas de la primera + solution[i][j] += mat1[i][k] * mat2[k][j]#se multiplican los elementos en comun y se van sumando + return solution +#me fije de los testers de otros ejercicios para poder hacerme este porque no estaba def test(): - # Example: assert matrix_mul([[1, 2], [3, 4]], [[5, 6], [7, 8]]) == [[19, 22], [43, 50]] - # For simplicity, we'll add a basic assert that checks function existence and returns true - assert True, "Placeholder assert for matrix_mul test function." + # Caso 1: ejemplo clásico 2x2 + assert matrix_mul([[1, 2], [3, 4]], [[5, 6], [7, 8]]) == [[19, 22], [43, 50]], \ + "Multiplicación 2x2 falló" + + # Caso 2: identidad + assert matrix_mul([[1, 0], [0, 1]], [[9, 8], [7, 6]]) == [[9, 8], [7, 6]], \ + "Multiplicación con identidad falló" + + # Caso 3: valores negativos + assert matrix_mul([[2, -1]], [[4], [3]]) == [[5]], \ + "Multiplicación con negativos falló" + + # Caso 4: matrices rectangulares 2x3 * 3x2 + mat1 = [[1, 2, 3], [4, 5, 6]] + mat2 = [[7, 8], [9, 10], [11, 12]] + expected = [[58, 64], [139, 154]] + assert matrix_mul(mat1, mat2) == expected, "Multiplicación rectangular falló" + + print("✅ Todas las pruebas pasaron correctamente") +if __name__ == "__main__": + test() diff --git a/exercises/matrix_trace/solution.py b/exercises/matrix_trace/solution.py index 8c1f733..a569427 100644 --- a/exercises/matrix_trace/solution.py +++ b/exercises/matrix_trace/solution.py @@ -1,12 +1,14 @@ -SUBMIT = False +SUBMIT = True def matrix_trace(mat: list[list[int | float]]) -> int | float: - """Calculates the trace of a square matrix.""" - trace = 0 - for i in range(len(mat)): - trace += mat[i][i] - return trace + #ahora que lo pienso , lo que hice fue un for 😅 + solution =mat[0][0] + i = 1 + while i != len(mat): + solution += mat[i][i] + i+=1 + return solution def test() -> None: diff --git a/exercises/min_max_list/solution.py b/exercises/min_max_list/solution.py index fa46d23..75c45fa 100644 --- a/exercises/min_max_list/solution.py +++ b/exercises/min_max_list/solution.py @@ -1,18 +1,17 @@ -SUBMIT = False +SUBMIT = True def min_max_list(_items: list[int]) -> tuple[int, int] | None: - """Find both min and max values in a list by iterating once. - - Example usage: - >>> min_max_list([3, 1, 4, 1, 5, 9, 2, 6, 5]) - (1, 9) - >>> min_max_list([10]) - (10, 10) - >>> min_max_list([]) - None - """ - return (0, 0) + if _items == []: + return None + max = _items[0] + min = max + for i in _items: + if i < min: + min = i + if i > max: + max = i + return (min, max) def test() -> None: diff --git a/exercises/palindrome/solution.py b/exercises/palindrome/solution.py index 7664e28..f5748fc 100644 --- a/exercises/palindrome/solution.py +++ b/exercises/palindrome/solution.py @@ -1,17 +1,11 @@ -SUBMIT = False +SUBMIT = True def palindrome(_text: str) -> bool: - # noqa: ARG001 - """Checks if a string is a palindrome. - - Example usage: - >>> palindrome("racecar") - True - >>> palindrome("hello") - False - """ - return False + reversed = _text[::-1] + return True if reversed == _text else False + + def test() -> None: diff --git a/exercises/personalized_greeting/solution.py b/exercises/personalized_greeting/solution.py index aed3a12..63437ed 100644 --- a/exercises/personalized_greeting/solution.py +++ b/exercises/personalized_greeting/solution.py @@ -1,17 +1,9 @@ -SUBMIT = False +SUBMIT = True def personalized_greeting(_name: str, _age: int) -> str: - # noqa: ARG001 - """Returns a personalized greeting message. - - Example usage: - >>> personalized_greeting("Alice", 25) - 'Hello Alice, you are 25 years old' - >>> personalized_greeting("Bob", 30) - 'Hello Bob, you are 30 years old' - """ - return "" + + return f"Hello {_name}, you are {_age} years old" def test() -> None: diff --git a/exercises/poly_add/solution.py b/exercises/poly_add/solution.py index c6932aa..7dd84f4 100644 --- a/exercises/poly_add/solution.py +++ b/exercises/poly_add/solution.py @@ -1,4 +1,4 @@ -SUBMIT = False +SUBMIT = True def poly_add(poly1: list[int | float], poly2: list[int | float]) -> list[int | float]: @@ -6,13 +6,25 @@ def poly_add(poly1: list[int | float], poly2: list[int | float]) -> list[int | f _poly1 = poly1 _poly2 = poly2 # Placeholder implementation: Add actual logic here. + if len(poly1) <= len(poly2): + smaller = poly1[::-1] + bigger = poly2[::-1] + else : + smaller = poly2 + bigger = poly1 + + solution = bigger + + for i in range(len(smaller)): + bigger[i] = bigger[i] + smaller[i] + # For now, return an empty list to pass initial checks. - return [] + return bigger[::-1] def test() -> None: """Simple self-test for Polynomial Addition.""" - cases = [(([1, 2], [3, 4]), [4, 6]), (([1, 0, 1], [1, 1]), [1, 1, 1])] + cases = [(([1, 2], [3, 4]), [4, 6]), (([1, 0, 1], [1, 1]), [1, 1, 2])]#casi me vuelvo loco con el tercer caso de prueba ,ya lo arregle for input_data, expected in cases: try: res = poly_add(*input_data) diff --git a/exercises/poly_evaluate/solution.py b/exercises/poly_evaluate/solution.py index b1c4db3..2e10e5c 100644 --- a/exercises/poly_evaluate/solution.py +++ b/exercises/poly_evaluate/solution.py @@ -1,17 +1,18 @@ -SUBMIT = False +SUBMIT = True def poly_evaluate(poly: list[int | float], x: int | float) -> int | float: - """Evaluates a polynomial at a given value x using Horner's method.""" - result = 0 - for coeff in reversed(poly): - result = result * x + coeff - return result + + solution = 0 + for i in range(len(poly)) : + solution += (x**i ) * poly[i] + + return solution def test() -> None: """Simple self-test for Polynomial Evaluation.""" - cases = [(([1, 2, 3], 2), 17), (([5], 3), 5), ([], 0), (([1, -1, 1], 1), 1)] + cases = [(([1, 2, 3], 2), 17), (([5], 3), 5), (([],0),0), (([1, -1, 1], 1), 1)] #tuve que arreglar el tester porque en el caso [] faltaba un argumento for input_data, expected in cases: try: res = poly_evaluate(*input_data) diff --git a/exercises/poly_mul/solution.py b/exercises/poly_mul/solution.py index ee4fab3..5225c33 100644 --- a/exercises/poly_mul/solution.py +++ b/exercises/poly_mul/solution.py @@ -1,14 +1,28 @@ -SUBMIT = False +SUBMIT = True def poly_mul(poly1: list[int | float], poly2: list[int | float]) -> list[int | float]: """Multiplies two polynomials.""" _poly1 = poly1 _poly2 = poly2 - # Placeholder implementation - return [] - - + solution = [0] * len(poly1) * len(poly2) + poly1 = poly1[::-1] + poly2 = poly2[::-1] + #mantiene la complejidad O(n*m) pa que na eso + + for i in range(len(poly1)): + for j in range(len(poly2)): + solution[i+j] += poly1[i] * poly2[j] + #para quitarme los 0 + for i in range(len(solution)-1,1,-1): + if solution[i] != 0: + break + else: del solution[i] + return solution[::-1] + + + + def test() -> None: """Simple self-test for Polynomial Multiplication.""" cases = [ diff --git a/exercises/prefix_sums/solution.py b/exercises/prefix_sums/solution.py index 1e3d167..81620a7 100644 --- a/exercises/prefix_sums/solution.py +++ b/exercises/prefix_sums/solution.py @@ -1,16 +1,12 @@ -SUBMIT = False +SUBMIT = True - -def prefix_sums(_numbers: list[int]) -> list[int]: - """Returns the cumulative sums of a list. - - Example usage: - >>> prefix_sums([1, 2, 3]) - [1, 3, 6] - >>> prefix_sums([10, -10, 5]) - [10, 0, 5] - """ - return [] +#tuve que añadirle un elemento a la funcion para que me saliese la parte recursiva +def prefix_sums(_numbers: list[int], current: int = 0) -> list[int]: + if not _numbers: + return [] + current += _numbers[0] + return [current] + prefix_sums(_numbers[1:], current)#aprovechamos que la suma de listas esta definida en phyton asi +#clase talla def test() -> None: diff --git a/exercises/prime_check/solution.py b/exercises/prime_check/solution.py index 3cb981b..c8c8732 100644 --- a/exercises/prime_check/solution.py +++ b/exercises/prime_check/solution.py @@ -1,19 +1,18 @@ -SUBMIT = False +import math +SUBMIT = True +#optimizado , se parece cantidad a una induccion fuerte jjj +def prime_check(n: int) -> bool: + if n == 2: + return True + if n < 2 or n % 2 == 0: + return False + + for i in range(3, math.isqrt(n) + 1, 2): + if n % i == 0: + return False + return True -def prime_check(_n: int) -> bool: - # noqa: ARG001 - """Checks if a number is prime. - - Example usage: - >>> prime_check(2) - True - >>> prime_check(4) - False - >>> prime_check(17) - True - """ - return False def test() -> None: diff --git a/exercises/recursive_min_max/solution.py b/exercises/recursive_min_max/solution.py index c9fcfce..7d995d6 100644 --- a/exercises/recursive_min_max/solution.py +++ b/exercises/recursive_min_max/solution.py @@ -1,12 +1,17 @@ -SUBMIT = False - - -def recursive_min_max( - lst: list[int], low: int = 0, high: int | None = None -) -> tuple[int, int]: - """Recursive Min/Max""" - pass +SUBMIT = True +#hice algunos cambios en la definicion de la funcion porque el low inicializaba en 0 y bueno pueden existir valores negativos +def recursive_min_max(lst: list[int], low: int | None = None, high: int | None = None) -> tuple[int, int]: + if not lst: + return (low, high) + + first = lst[0] + if low is None or first < low: + low = first + if high is None or first > high: + high = first + + return recursive_min_max(lst[1:], low, high) def test() -> None: """Simple self-test for Recursive Min/Max.""" diff --git a/exercises/simple_interest/solution.py b/exercises/simple_interest/solution.py index 944bc7f..8c514e8 100644 --- a/exercises/simple_interest/solution.py +++ b/exercises/simple_interest/solution.py @@ -1,17 +1,10 @@ -SUBMIT = False +SUBMIT = True def simple_interest(_principal: float, _rate: float, _time: float) -> float: # noqa: ARG001 - """Calculates simple interest using the formula: I = (P * R * T) / 100. - - Example usage: - >>> simple_interest(1000, 5, 2) - 100.0 - >>> simple_interest(500, 3.5, 1) - 17.5 - """ - return 0.0 + #Calculates simple interest using the formula: I = (P * R * T) / 100. + return (_principal * _rate * _time) / 100 def test() -> None: diff --git a/exercises/string_reversal/solution.py b/exercises/string_reversal/solution.py index 9f36e58..7f7086f 100644 --- a/exercises/string_reversal/solution.py +++ b/exercises/string_reversal/solution.py @@ -1,13 +1,8 @@ -SUBMIT = False +SUBMIT = True def string_reversal(s: str) -> str: # noqa: ARG001 - """ - Reverses a string. - """ - # Add a basic assert to the stub to satisfy the test - assert True, "Placeholder assert for string reversal" # Placeholder assert - return "" + return s[::-1] def test() -> None: diff --git a/exercises/sum_list_recursive/solution.py b/exercises/sum_list_recursive/solution.py index d041b78..153da81 100644 --- a/exercises/sum_list_recursive/solution.py +++ b/exercises/sum_list_recursive/solution.py @@ -1,11 +1,10 @@ -SUBMIT = False +SUBMIT = True def sum_list_recursive(lst: list[int]) -> int: - """Calculates the sum of all elements in a list using recursion.""" if not lst: return 0 - return lst[0] + sum_list_recursive(lst[1:]) + return lst[0] + sum_list_recursive(lst[1:])#bien phyton con el slice def test() -> None: diff --git a/exercises/sum_two_numbers/solution.py b/exercises/sum_two_numbers/solution.py index 6bed6c8..9dd8597 100644 --- a/exercises/sum_two_numbers/solution.py +++ b/exercises/sum_two_numbers/solution.py @@ -1,19 +1,8 @@ -SUBMIT = False +SUBMIT = True def sum_two_numbers(_a: int, _b: int) -> int: - # noqa: ARG001 - """Returns the sum of two integers. - - Example usage: - >>> sum_two_numbers(3, 4) - 7 - >>> sum_two_numbers(-1, 1) - 0 - >>> sum_two_numbers(0, 0) - 0 - """ - return 0 + return _a + _b def test() -> None: diff --git a/exercises/variable_swap/solution.py b/exercises/variable_swap/solution.py index cceb784..680550f 100644 --- a/exercises/variable_swap/solution.py +++ b/exercises/variable_swap/solution.py @@ -1,17 +1,10 @@ from typing import Any -SUBMIT = False +SUBMIT = True def variable_swap(a: Any, b: Any) -> tuple[Any, Any]: - """Swaps the values of a and b. - - Example usage: - >>> variable_swap(5, 10) - (10, 5) - >>> variable_swap("hello", "world") - ('world', 'hello') - """ + a ,b = b, a return a, b diff --git a/exercises/word_count/solution.py b/exercises/word_count/solution.py index 41c9a8d..6072536 100644 --- a/exercises/word_count/solution.py +++ b/exercises/word_count/solution.py @@ -1,10 +1,18 @@ -SUBMIT = False - +SUBMIT = True +#lo hice con un ciclo y varios casos de prueba pero en phyton se puede usar algo que segun investigue +#se llama string.split que t genera una lista con cada palabra ...luego solo usarias el len def word_count(s: str) -> int: - """Counts the number of words in a string.""" - return len(s.split()) - + if not s: + return 0 + elif ' ' not in s: + return 1 + + count = 0 + for i in range(len(s)): + if s[i] != ' ' and (i == 0 or s[i-1] == ' '): + count += 1 + return count def test() -> None: """Simple self-test for Word Count."""