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
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.fontSize": 12,
"files.autoSave": "afterDelay"
}
16 changes: 13 additions & 3 deletions exercises/binary_search_recursive/solution.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
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
if high is None :
high = len(lst) - 1
if low > high :
return -1
medio = (low + high) //2
if lst[medio] == target :
return medio
else :
if lst[medio] < target :
return binary_search_recursive(lst, target, medio + 1, high)
elif lst[medio] > target :
return binary_search_recursive(lst, target,low, medio - 1)


def test() -> None:
Expand Down
2 changes: 1 addition & 1 deletion exercises/char_frequency/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def char_frequency(s: str) -> dict[str, int]:
Expand Down
15 changes: 15 additions & 0 deletions exercises/count_vowels/solution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import ast
from pathlib import Path


def count_vowels(s: str) -> int :
a = 0
if len(str) == 0 :
return 0



s = s.lower()
if s[0] == 'a' or s[0] == 'e' or s[0] == 'i' or s[0] == 'o' or s[0] == 'u' :
a +=1
return s[1::]



def test_exercise_solutions_have_asserts() -> None:
"""Verify that all exercise solution stubs have a test() function with asserts."""
root = Path(__file__).parent.parent
Expand Down
9 changes: 5 additions & 4 deletions exercises/factorial_tail/solution.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
SUBMIT = False
SUBMIT = True


def factorial_tail(n: int, acc: int = 1) -> int:
"""Tail Recursive Factorial"""
pass

if n == 0 :
return 1
else :
return factorial_tail(n-1, 1) * n

def test() -> None:
"""Simple self-test for Factorial Tail."""
Expand Down
8 changes: 5 additions & 3 deletions exercises/fast_exponentiation/solution.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
SUBMIT = False
SUBMIT = True


def fast_exponentiation(a: int, n: int) -> int:
"""Fast Exponentiation"""
pass
if n == 0 :
return 1
else :
return a * fast_exponentiation(a,n-1)


def test() -> None:
Expand Down
11 changes: 7 additions & 4 deletions exercises/fibonacci_tail/solution.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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
if n == 1 :
return 1
else :
return fibonacci_tail(n-1) + fibonacci_tail(n-2)

def test() -> None:
"""Simple self-test for Fibonacci Tail."""
Expand Down
7 changes: 6 additions & 1 deletion exercises/linear_search/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ def linear_search(_items: list[int], _target: int) -> int:
>>> 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
9 changes: 7 additions & 2 deletions exercises/list_average/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def list_average(_numbers: list[float]) -> float:
Expand All @@ -10,7 +10,12 @@ def list_average(_numbers: list[float]) -> float:
>>> list_average([10, 20, 30])
20.0
"""
return 0.0
promedio = 0
for c in _numbers :
promedio +=c

resultado = promedio / len(_numbers)
return resultado


def test() -> None:
Expand Down
10 changes: 7 additions & 3 deletions exercises/list_mode/solution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

SUBMIT = False
SUBMIT = True


def list_mode(_items: list[Any]) -> Any:
Expand All @@ -12,10 +12,14 @@ def list_mode(_items: list[Any]) -> Any:
>>> list_mode(['a', 'b', 'a'])
'a'
"""
return None
conteo = {}
for c in _items :
conteo[c] = conteo.get(c, 0) + 1
moda = max(conteo, key = conteo.get)
return moda


def test() -> None:
def test() -> None :
"""Simple self-test for Most Common Element."""
cases: list[tuple[list[Any], Any]] = [
([1, 2, 2, 3, 3, 3], 3),
Expand Down
8 changes: 6 additions & 2 deletions exercises/matrix_add/solution.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
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(mat2)):
mat1[i] += mat2[i]

return mat1


def test() -> None:
Expand Down
8 changes: 4 additions & 4 deletions exercises/matrix_trace/solution.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
SUBMIT = False
SUBMIT = True


def matrix_trace(mat: list[list[int | float]]) -> int | float:
"""Calculates the trace of a square matrix."""
trace = 0
traza = 0
for i in range(len(mat)):
trace += mat[i][i]
return trace
traza += mat[i][i]
return traza


def test() -> None:
Expand Down
18 changes: 16 additions & 2 deletions exercises/min_max_list/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def min_max_list(_items: list[int]) -> tuple[int, int] | None:
Expand All @@ -12,7 +12,21 @@ def min_max_list(_items: list[int]) -> tuple[int, int] | None:
>>> min_max_list([])
None
"""
return (0, 0)
if not _items :
return None
max = min = _items[0]

for i in range(len(_items)) :
if _items[i] > max :
max = _items[i]
if _items[i] < min :
min = _items[i]





return (min, max)


def test() -> None:
Expand Down
4 changes: 3 additions & 1 deletion exercises/palindrome/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def palindrome(_text: str) -> bool:
Expand All @@ -11,6 +11,8 @@ def palindrome(_text: str) -> bool:
>>> palindrome("hello")
False
"""
if _text == _text[::-1] :
return True
return False


Expand Down
3 changes: 2 additions & 1 deletion exercises/personalized_greeting/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def personalized_greeting(_name: str, _age: int) -> str:
>>> personalized_greeting("Bob", 30)
'Hello Bob, you are 30 years old'
"""
return ""

return f"Hello {_name}, you are {_age} years old"


def test() -> None:
Expand Down
19 changes: 16 additions & 3 deletions exercises/poly_add/solution.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
SUBMIT = False
SUBMIT = True


def poly_add(poly1: list[int | float], poly2: list[int | float]) -> list[int | float]:
"""Adds two polynomials."""
_poly1 = poly1
_poly2 = poly2
maxima_longitud = max(len(poly1), len(poly2))


final = [0 for j in range(maxima_longitud)]
for i in range(len(poly1)) :
final[i] += poly1[i]
for j in range(len(poly2)) :
final[j] += poly2[j]



if final[-1] == 0 :
final.pop()
# Placeholder implementation: Add actual logic here.
# For now, return an empty list to pass initial checks.
return []
return final


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]), [2, 1, 1])]
for input_data, expected in cases:
try:
res = poly_add(*input_data)
Expand Down
4 changes: 2 additions & 2 deletions exercises/poly_evaluate/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def poly_evaluate(poly: list[int | float], x: int | float) -> int | float:
Expand All @@ -11,7 +11,7 @@ def poly_evaluate(poly: list[int | float], x: int | float) -> int | float:

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)]
for input_data, expected in cases:
try:
res = poly_evaluate(*input_data)
Expand Down
1 change: 1 addition & 0 deletions exercises/poly_mul/README.es.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Multiplicación de Polinomios

## Contexto
Expand Down
12 changes: 10 additions & 2 deletions exercises/prefix_sums/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def prefix_sums(_numbers: list[int]) -> list[int]:
Expand All @@ -10,7 +10,15 @@ def prefix_sums(_numbers: list[int]) -> list[int]:
>>> prefix_sums([10, -10, 5])
[10, 0, 5]
"""
return []
if not _numbers :
return []
nueva_referencia = [_numbers[0]]
for i in range(1, len(_numbers)) :
nueva_referencia.append(nueva_referencia[i-1]+_numbers[i])

return nueva_referencia




def test() -> None:
Expand Down
13 changes: 10 additions & 3 deletions exercises/prime_check/solution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SUBMIT = False

SUBMIT = True
import math

def prime_check(_n: int) -> bool:
# noqa: ARG001
Expand All @@ -13,7 +13,14 @@ def prime_check(_n: int) -> bool:
>>> prime_check(17)
True
"""
return False
if _n < 2 :
return False
raice = math.sqrt(_n)

for i in range(2, int(raice)+1) :
if _n % i == 0 :
return False
return True


def test() -> None:
Expand Down
18 changes: 15 additions & 3 deletions exercises/recursive_min_max/solution.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
SUBMIT = False
SUBMIT = True


def recursive_min_max(
lst: list[int], low: int = 0, high: int | None = None
) -> tuple[int, int]:
"""Recursive Min/Max"""
pass
if len(lst) == 0 :
return None, None

if len(lst) == 1 :
return lst[0], lst[0]

medio = len(lst) // 2
mins, maxs = recursive_min_max(lst[:medio])
mink, mas = recursive_min_max(lst[medio:])
maximo = max(maxs, mas)
minimo = min(mins, mink)
return minimo, maximo




def test() -> None:
Expand Down
3 changes: 3 additions & 0 deletions exercises/simple_interest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def simple_interest(_principal: float, _rate: float, _time: float) -> float:
a= _principal* _rate * _time / 100
return a
Loading
Loading