Ejercicio: 3Eva_IT2000_T2 Matriz: puntos por goles en campeonato
Desarrollado en Python a partir el ejercicio 3Eva_IT2002_T1 Triunfos, empates y derrotas por Golesf
goles=np.array([[0, 3, 1, 2, 1],
[1, 0, 3, 2, 3],
[0, 2, 0, 1, 1],
[1, 0, 2, 0, 1],
[3, 4, 1, 2, 0]])
complementando la solución del ejercicio de triunfos empates y derrotas se obtiene para los datos ingresados:
triunfos por equipo:
[3 2 0 1 3]
empates por equipo:
[0 0 1 0 1]
derrotas por equipo:
[1 2 3 3 0]
puntos por equipo:
[ 9 6 1 3 10]
>>>
Algoritmo en Python
# 3Eva_IT2000_T2 Matriz: puntos por goles en campeonato
import numpy as np
# INGRESO
goles=np.array([[0, 3, 1, 2, 1],
[1, 0, 3, 2, 3],
[0, 2, 0, 1, 1],
[1, 0, 2, 0, 1],
[3, 4, 1, 2, 0]])
# PROCEDIMIENTO
tamano = np.shape(goles)
n = tamano[0]
m = tamano[1]
triunfos = np.zeros(shape=(n,m),dtype=int)
ttriunfos = np.zeros(n,dtype=int)
# calcular los triunfos
i = 0
while not(i>=n):
j = 0
while not(j>=m):
if (goles[i,j] > goles[j,i]):
triunfos[i,j] = 1
triunfos[j,i] = 0
j = j + 1
i = i + 1
# calcular total de triunfos
i = 0
while not(i>=n):
j = 0
while not(j>=m):
ttriunfos[i] = ttriunfos[i] + triunfos[i,j]
j = j + 1
i = i + 1
# calcular empates
empates = np.zeros(shape=(n,m),dtype=int)
tempates = np.zeros(n,dtype=int)
i = 0
while not(i>=n):
j = 0
while not(j>=m):
if (goles[i,j] == goles[j,i]) and (i!=j):
empates[i,j] = 1
empates[j,i] = 1
j = j + 1
i = i + 1
# calcular total de empates
i = 0
while not(i>=n):
j = 0
while not(j>=m):
tempates[i] = tempates[i] + empates[i,j]
j = j + 1
i = i + 1
# Derrotas
derrotas = (n-1)*np.ones(n,dtype=int)
derrotas = derrotas - ttriunfos - tempates
# puntos totales
puntos_triunfos = ttriunfos*3
puntos_empates = tempates*1
puntos = puntos_triunfos+puntos_empates
# SALIDA
print(triunfos)
print(' triunfos por equipo: ')
print(ttriunfos)
print(' empates por equipo:')
print(tempates)
print(' derrotas por equipo:')
print(derrotas)
print('puntos por equipo:')
print(puntos)