Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions exercises/binary_search_recursive/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
27 changes: 11 additions & 16 deletions exercises/case_inverter/solution.py
Original file line number Diff line number Diff line change
@@ -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"),
]
Expand Down
16 changes: 3 additions & 13 deletions exercises/celsius_to_fahrenheit/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
12 changes: 6 additions & 6 deletions exercises/char_frequency/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
29 changes: 25 additions & 4 deletions exercises/count_vowels/solution.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down Expand Up @@ -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()
17 changes: 5 additions & 12 deletions exercises/factorial_iterative/solution.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down
7 changes: 4 additions & 3 deletions exercises/factorial_tail/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 13 additions & 4 deletions exercises/fast_exponentiation/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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()
28 changes: 14 additions & 14 deletions exercises/fibonacci/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
11 changes: 8 additions & 3 deletions exercises/fibonacci_tail/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
11 changes: 3 additions & 8 deletions exercises/hello_world/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 5 additions & 12 deletions exercises/linear_search/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 7 additions & 10 deletions exercises/list_average/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
35 changes: 22 additions & 13 deletions exercises/list_mode/solution.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Loading
Loading