Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATRICIO GPE DELGADO TREJO Primera practica #191

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions ago-dic-2024/PATRICIO GPE DELGADO TREJO/PROBLEMA1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def quicksort(arr, start, end, color_order):
if start < end:
pivot_index = partition(arr, start, end, color_order)
quicksort(arr, start, pivot_index - 1, color_order)
quicksort(arr, pivot_index + 1, end, color_order)

def partition(arr, start, end, color_order):
pivot = arr[end]
i = start - 1
for j in range(start, end):
if (color_order.index(arr[j][0]), arr[j][1]) < (color_order.index(pivot[0]), pivot[1]):
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[end] = arr[end], arr[i + 1]
return i + 1

n = int(input("INGRESE LA CANTIDAD DE COLORES ENTER Y LUEGO SU NOMBRE Y SU CANTIDAD"))
markers = [input().split('-') for _ in range(n)]
markers = [(color, int(dilution)) for color, dilution in markers]

color_order = ["Rojo", "Anaranjado", "Amarillo", "Verde", "Indigo", "Violeta", "Azul"]
quicksort(markers, 0, n - 1, color_order)
print("ORDENADO")
for color, dilution in markers:
print(f"{color}-{dilution}")
18 changes: 18 additions & 0 deletions ago-dic-2024/PATRICIO GPE DELGADO TREJO/PROBLEMA2.PY
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def counting_sort(arr):
max_val = max(arr)
count = [0] * (max_val + 1)

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

sorted_arr = []
for i in range(len(count)):
sorted_arr.extend([i] * count[i])

return sorted_arr

n = int(input("INGRESE LA CANTIDAD DE NUMEROS: "))
arr = list(map(int, input("INGRESEE LOS NUMEROS SEPARADOS POR ESPACIOS: ").split()))
sorted_arr = counting_sort(arr)
print("ORDENADOS")
print(" ".join(map(str, sorted_arr)))
4 changes: 4 additions & 0 deletions ago-dic-2024/PATRICIO GPE DELGADO TREJO/practica1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
n1=float(input("Intro número uno: "))
n2=float(input("Intro numero dos: "))
suma=n1+n2
print(suma)