Created
September 3, 2022 19:26
-
-
Save icarofreire/5d0f9b63b8338c34ce9a00011d2750d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~ def sum(arr, sub): | |
# ~ con = 0 | |
# ~ maxi = 0 | |
# ~ for i in arr: | |
# ~ if con < sub: | |
# ~ maxi += i | |
# ~ con+=1 | |
# ~ return [maxi, arr[:sub], some] | |
# ~ return [sub, arr[:sub]] | |
# ~ def solve(arr): | |
# ~ n = len(arr) | |
# ~ arr.sort(reverse=True) | |
# ~ rest = [] | |
# ~ if n > 2: | |
# ~ for s in range(0, n): | |
# ~ arran = sum(arr, s) | |
# ~ if s > 0: | |
# ~ print(s, arran[0], arran[1], arran[2][s], s) | |
# ~ print(s, arran[1]) | |
# ~ rest.append(arran[1]) | |
# ~ rest[1].sort() | |
# ~ return rest[1] | |
# ~ else: | |
# ~ return arr | |
# ~ arr = [3,7,5,6,2] | |
# ~ arr = [6,5,3,2,4,1,2] | |
# ~ arr = [5,4,2,5,1,6] | |
# ~ arr = [500,500] | |
# ~ print(solve(arr)) | |
# ******************** | |
# 2 grupos; | |
n = 4 | |
related = [ | |
['1','1','0','0'], | |
['1','1','1','0'], | |
['0','1','1','0'], | |
['0','0','0','1'], | |
] | |
# ~ n = 5 # 5 grupos; | |
# ~ related = [ | |
# ~ ['1','0','0','0','0'], | |
# ~ ['0','1','0','0','0'], | |
# ~ ['0','0','1','0','0'], | |
# ~ ['0','0','0','1','0'], | |
# ~ ['0','0','0','0','1'], | |
# ~ ] | |
# ~ n = 5 # grupos; | |
# ~ related = [ | |
# ~ ['1','0','0','0','0'], | |
# ~ ['0','1','0','0','0'], | |
# ~ ['0','0','1','0','0'], | |
# ~ ['0','0','1','0','0'], | |
# ~ ['1','0','0','0','0'], | |
# ~ ] | |
visi = [] | |
path = {} | |
def filhos(related, n, i): | |
# ~ print(i) | |
for j in range(0, n): | |
if( j not in visi and related[i][j] == '1' ): | |
# ~ print(i, '->', j, visi) | |
visi.append(j) | |
filhos(related, n, j) | |
indi=-1 | |
indj=-1 | |
conhe = [] | |
simesmo = [] | |
# ~ filhos(related, n, 0) | |
# ~ print(visi) | |
gg = [] | |
for i in range(0, n): | |
filhos(related, n, i) | |
visi.sort() | |
if(visi not in gg): gg.append(visi) | |
# ~ gg.append(visi) | |
# ~ print(visi) | |
visi = [] | |
for g in gg: print(g) | |
# ~ for i in range(0, n): | |
# ~ filhos(related, n, i) | |
# ~ indi+=1 | |
# ~ for j in range(0, n): | |
# ~ indj+=1 | |
# ~ print([i, j], related[i][j]) | |
# ~ if( i != j and related[i][j] == '1' ): | |
# ~ if i not in conhe: conhe.append(i) | |
# ~ if j not in conhe: conhe.append(j) | |
# ~ print([i,j], related[i][j], '<<') | |
# ~ elif( i == j and related[i][j] == '1' ): | |
# ~ print([i,j], related[i][j], '==') | |
# ~ if i not in simesmo: simesmo.append(i) | |
# ~ if j not in simesmo: simesmo.append(j) | |
""" | |
verysimesmo = [] | |
for si in simesmo: | |
if si not in conhe: verysimesmo.append(si) | |
print('***') | |
print(conhe) | |
print(simesmo) | |
print(verysimesmo) | |
# dos que se conhece, mas nunca enviiou um para o outro; | |
nenv = 0 | |
naoamigos = [] | |
nuncaenv = [] | |
env = [] | |
for i in conhe: | |
for j in conhe: | |
if i != j and related[i][j] != '1': | |
nenv += 1 | |
print(i,'->',j) | |
if i not in nuncaenv: nuncaenv.append(i) | |
if j not in nuncaenv: nuncaenv.append(j) | |
if i != j and related[i][j] == '1': | |
print(i,'=->',j) | |
if i not in env: env.append(i) | |
if j not in env: env.append(j) | |
# ~ print( naoamigos ) | |
joinedlist = nuncaenv + env | |
# \/ conhecidos, direta ou indiretamente; | |
conhecidos = list(set(joinedlist)) | |
print(nuncaenv) | |
print(env) | |
print(conhecidos) | |
if( conhecidos == env ): | |
print(env) | |
grupo = 0 | |
# ~ if(len(conhe) > 0): grupo+=1 | |
if(len(verysimesmo) > 0): grupo += len(verysimesmo) | |
grupo += nenv | |
# ~ print(verysimesmo, len(verysimesmo) + grupo) | |
print('grupos: ', grupo) | |
# ~ print(filhos(related, n, 3)) | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment