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
1 change: 1 addition & 0 deletions AlgoritmosSistemas
Submodule AlgoritmosSistemas added at 502bc2
16 changes: 16 additions & 0 deletions ago-dic-2024/insertionsort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def insertion_sort(arr):

for i in range(1, len(arr)):
llave = arr[i]
j = i - 1

if j >= 0 and arr[j] > llave:
arr[j + 1] = arr[j]
j -= 1

arr[j + 1] = llave


arr = [4, 3, 2, 10, 12, 1, 5, 6]
insertion_sort(arr)
print(arr)
29 changes: 29 additions & 0 deletions ago-dic-2024/parcial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Angel Ricardo Villalpando Ramirez
#Ejercicio 1
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]

n = int(input())
medicinas = input().split()

bubble_sort(medicinas)
print(" ".join(medicinas))

#Ejercicio 2 #########################################################################

n = int(input())
entrada = input().split()

medicinas = []
for i in range(0, len(entrada), 2):
nombre_medicina = entrada[i]
cantidad_pastillas = int(entrada[i+1])
medicinas.append((nombre_medicina, cantidad_pastillas))

medicinas.sort(key=lambda x: x[1], reverse=True)

print(" ".join([medicina[0] for medicina in medicinas]))
39 changes: 39 additions & 0 deletions ago-dic-2024/parcial2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#Ejercicio 1
rainbow_order = ["Rojo", "Anaranjado", "Amarillo", "Verde", "Indigo", "Violeta", "Azul"]

color_priority = {color: index for index, color in enumerate(rainbow_order)}

n = int(input().strip())

markers = []
for _ in range(n):
s = input().strip()
color, level = s.split("-")
level = int(level)
markers.append((color, level, s))


markers.sort(key=lambda x: (color_priority[x[0]], x[1]))

for marker in markers:
print(marker[2])


print("")
print("Ejercicio 2")
#Ejercicio 2
n = int(input().strip())
numbers = list(map(int, input().strip().split()))

max_value = max(numbers)

count = [0] * (max_value + 1)

for number in numbers:
count[number] += 1

sorted_numbers = []
for value, freq in enumerate(count):
sorted_numbers.extend([value] * freq)

print(" ".join(map(str, sorted_numbers)))
44 changes: 44 additions & 0 deletions ago-dic-2024/practica2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
def insertion_sort(arr):
n = len(arr)
for i in range(1, n):
key = arr[i]
j = i - 1
# Mueve los elementos del arreglo que son mayores que key a una posición adelante
while j >= 0 and arr[j] > key:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key

def max_problems_solved(n, m, times):
# Ordenar los tiempos con insertion sort
insertion_sort(times)

total_time = 0
problems_solved = 0

# Sumar tiempos hasta que no tengamos más tiempo disponible
for time in times:
if total_time + time <= m:
total_time += time
problems_solved += 1
else:
break

return problems_solved

try:
# Entrada
n, m = map(int, input("Introduce n y m separados por un espacio: ").split()) # Leer n y m
times = list(map(int, input(f"Introduce {n} tiempos separados por espacios: ").split())) # Leer los tiempos de cada problema

if len(times) != n:
raise ValueError(f"Se esperaban {n} tiempos, pero se recibieron {len(times)}.")

# Resolver el problema
result = max_problems_solved(n, m, times)

# Salida
print(result)

except ValueError as e:
print(f"Error en la entrada: {e}")
21 changes: 21 additions & 0 deletions ago-dic-2024/practica3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def selection_sort_desc(arr):
n = len(arr)
for i in range(n):
# Encontrar el índice del valor máximo en el resto de la lista
max_idx = i
for j in range(i + 1, n):
if arr[j] > arr[max_idx]:
max_idx = j
# Intercambiar el elemento máximo encontrado con el primer elemento no ordenado
arr[i], arr[max_idx] = arr[max_idx], arr[i]

# Leer la entrada
n = int(input()) # Número de Pokemons
powers = list(map(int, input().split())) # Lista de poderes de los Pokemons

# Ordenar la lista de poderes en orden descendente
selection_sort_desc(powers)

# Imprimir la lista ordenada
print(" ".join(map(str, powers)))

40 changes: 40 additions & 0 deletions ago-dic-2024/practica4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
def merge_sort(lst):
if len(lst) > 1:
mid = len(lst) // 2
left_half = lst[:mid]
right_half = lst[mid:]

merge_sort(left_half)
merge_sort(right_half)

i = j = k = 0

while i < len(left_half) and j < len(right_half):
if left_half[i] < right_half[j]:
lst[k] = left_half[i]
i += 1
else:
lst[k] = right_half[j]
j += 1
k += 1

while i < len(left_half):
lst[k] = left_half[i]
i += 1
k += 1

while j < len(right_half):
lst[k] = right_half[j]
j += 1
k += 1

def main():
n = int(input())
words = input().split()

merge_sort(words)

print(" ".join(words))

if __name__ == "__main__":
main()
65 changes: 65 additions & 0 deletions ago-dic-2024/practica5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
def merge_sort(libros):
if len(libros) > 1:
<<<<<<< HEAD
=======

>>>>>>> 88c5fc63042c95d5c09e2842f5feb05cb084c5c5
mid = len(libros) // 2
left_half = libros[:mid]
right_half = libros[mid:]

merge_sort(left_half)
merge_sort(right_half)

i = j = k = 0

while i < len(left_half) and j < len(right_half):
if left_half[i][1] < right_half[j][1]:
libros[k] = left_half[i]
i += 1
else:
libros[k] = right_half[j]
j += 1
k += 1

<<<<<<< HEAD

=======
>>>>>>> 88c5fc63042c95d5c09e2842f5feb05cb084c5c5
while i < len(left_half):
libros[k] = left_half[i]
i += 1
k += 1

while j < len(right_half):
libros[k] = right_half[j]
j += 1
k += 1

<<<<<<< HEAD

n = int(input())
libros = []


=======
n = int(input())
libros = []

>>>>>>> 88c5fc63042c95d5c09e2842f5feb05cb084c5c5
for _ in range(n):
entrada = input().split()
nombre_libro = entrada[0]
paginas = int(entrada[1])
libros.append((nombre_libro, paginas))

<<<<<<< HEAD

merge_sort(libros)


=======
merge_sort(libros)

>>>>>>> 88c5fc63042c95d5c09e2842f5feb05cb084c5c5
print(" ".join([libro[0] for libro in libros]))
16 changes: 16 additions & 0 deletions ago-dic-2024/practica6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def quick_sort(arr):
if len(arr) <= 1:
return arr
else:
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quick_sort(left) + middle + quick_sort(right)

n = int(input().strip())
color_ids = list(map(int, input().strip().split()))

sorted_colors = quick_sort(color_ids)

print(" ".join(map(str, sorted_colors)))
6 changes: 6 additions & 0 deletions ago-dic-2024/practicas/practica_1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ Salida:
`10`

Todo esto por entrada y salida estandar (system.out, system.in)






11 changes: 11 additions & 0 deletions ago-dic-2024/practicas/practica_1/practica1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
entrada = input("Ingresa dos números enteros separados por un espacio: ")

# Dividimos la entrada en dos números
numero1, numero2 = map(int, entrada.split())

# Calculamos la suma
suma = numero1 + numero2

# Mostramos el resultado
print(f"La suma de {numero1} y {numero2} es: {suma}")