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
32 changes: 32 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/Parcial2_P1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
rainbow_order = ["Rojo", "Anaranjado", "Amarillo", "Verde", "Azul", "Indigo", "Violeta"]

def key_func(marker):
color, dilution = marker.split('-')
dilution = int(dilution)
color_order = rainbow_order.index(color)
return color_order, dilution

def quicksort(markers, low, high):
if low < high:
pivot_index = partition(markers, low, high)
quicksort(markers, low, pivot_index - 1)
quicksort(markers, pivot_index + 1, high)

def partition(markers, low, high):
pivot = markers[high]
i = low - 1
for j in range(low, high):
if key_func(markers[j]) < key_func(pivot):
i += 1
markers[i], markers[j] = markers[j], markers[i]
markers[i + 1], markers[high] = markers[high], markers[i + 1]
return i + 1

def sort_markers(markers):
quicksort(markers, 0, len(markers) - 1)
for marker in markers:
print(marker)

n = int(input())
markers = [input().strip() for _ in range(n)]
sort_markers(markers)
19 changes: 19 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/Parcial2_P2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def counting_sort(arr):
max_val = max(arr)

count = [0] * (max_val + 1)

for num in arr:
count[num] += 1

sorted_arr = []
for num, freq in enumerate(count):
sorted_arr.extend([num] * freq)

return sorted_arr

n = int(input())
arr = list(map(int, input().split()))

sorted_arr = counting_sort(arr)
print(" ".join(map(str, sorted_arr)))
37 changes: 37 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/Practica4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
left_half = arr[:mid]
right_half = arr[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]:
arr[k] = left_half[i]
i += 1
else:
arr[k] = right_half[j]
j += 1
k += 1

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

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

def main():
n = int(input().strip())
words = input().strip().split()
merge_sort(words)
print(" ".join(words))
if __name__ == "__main__":
main()
43 changes: 43 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/Practica5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def merge_sort_books(books):
if len(books) > 1:
mid = len(books) // 2
left_half = books[:mid] # Se divide la primera parte
right_half = books[mid:] # Se divide la segunda mitad
merge_sort_books(left_half)
merge_sort_books(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]:
books[k] = left_half[i]
i += 1
else:
books[k] = right_half[j]
j += 1
k += 1

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

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

def main():
n = int(input().strip())
books = []
for _ in range(n):
data = input().strip().split()
title = " ".join(data[:-1])
pages = int(data[-1])
books.append((title, pages))

merge_sort_books(books)

sorted_titles = [book[0] for book in books]
print(" ".join(sorted_titles))
if __name__ == "__main__":
main()
16 changes: 16 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/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

pivot = arr[0]

menores = [x for x in arr[1:] if x <= pivot]
mayores = [x for x in arr[1:] if x > pivot]

return quick_sort(menores) + [pivot] + quick_sort(mayores)

n = int(input())
ids = list(map(int, input().split()))
ordenados = quick_sort(ids)

print(" ".join(map(str, ordenados)))
11 changes: 11 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/parcial1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#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("Número de medicinas: "))
medicinas= list (map(int, input("Nombre de las medicinas: ").split()))
bubble_sort(medicinas)
print(" ".join(map(str, medicinas)))
15 changes: 15 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/parcial1_ej2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n - i - 1):
if arr[j][1] < arr[j + 1][1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]

n = int(input("Número de medicinas: "))
data = input("Nombre de las medicinas y sus cantidades: ").split()

medicinas = [(data[i], int(data[i + 1])) for i in range(0, 2 * n, 2)]

bubble_sort(medicinas)
resultado = [medicina[0] for medicina in medicinas]
print(" ".join(resultado))
6 changes: 6 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/practica1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
entrada = input("Ingrese 2 números16 que desee sumar: ")
num1, num2 = map(int, entrada.split())

suma = num1 + num2

print(suma)
37 changes: 37 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/practica2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def insertion_sort(arr):
# Ordena el arreglo utilizando el algoritmo de Insertion Sort
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and arr[j] > key:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key

def max_problems(n, m, times):
# Ordenar los tiempos de los problemas
insertion_sort(times)

count = 0
total_time = 0

# Calcular cuántos problemas puede resolver David
for time in times:
if total_time + time <= m:
total_time += time
count += 1
else:
break

return count, total_time

# Leer la entrada
entrada = input("Ingrese n y m: ")
n, m = map(int, entrada.split())
tiempos = list(map(int, input("Ingrese los tiempos de los problemas: ").split()))

# Obtener la cantidad máxima de problemas y el tiempo total
cantidad_problemas, tiempo_total = max_problems(n, m, tiempos)

# Imprimir el resultado
print(cantidad_problemas)
17 changes: 17 additions & 0 deletions ago-dic-2024/practicas/Sarahí Coronado Carrión/practica3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def bubble_sort(arr):
n = len(arr)
# Implementación del algoritmo Bubble Sort
for i in range(n):
for j in range(0, n - i - 1):
if arr[j] < arr[j + 1]: # Ordenar de mayor a menor
arr[j], arr[j + 1] = arr[j + 1], arr[j]

# Leer la entrada
n = int(input("Ingrese el número de pokemons: "))
poderes = list(map(int, input("Ingrese los poderes de los pokemons: ").split()))

# Ordenar los poderes de los pokemons
bubble_sort(poderes)

# Imprimir la salida
print(" ".join(map(str, poderes)))
7 changes: 7 additions & 0 deletions ago-dic-2024/practicas/practica_1/practica_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

entrada = input("Ingrese 2 números16 que desee sumar: ")
num1, num2 = map(int, entrada.split())

suma = num1 + num2

print(suma)