amis_communs.py

Created by gilles-dhaussy

Created on December 18, 2023

971 Bytes


tableau_adjacence = [
[0,1,1,0,0,0,0,1,0,0],
[1,0,1,0,0,1,0,0,0,0],
[1,1,0,1,0,0,0,0,1,0],
[0,0,1,0,1,1,0,0,0,1],
[0,0,0,1,0,0,1,0,1,0],
[0,1,0,1,0,0,1,0,0,0],
[0,0,0,0,1,1,0,1,0,0],
[1,0,0,0,0,0,1,0,0,1],
[0,0,1,0,1,0,0,0,0,1],
[0,0,0,1,0,0,0,1,1,0]]

def aff_tableau(tableau):
  for ligne in tableau:
    print(ligne)

def algo1(tableau):
  n = len(tableau)
  amis_communs = [
    [0 for i in range(n)]
    for i in range(n)]
  for i in range(n):
    for j in range(n):
      if i!=j:
        for k in range(n):
          if (tableau[i][k]==1
          and tableau[k][j]==1):
            amis_communs[i][j] += 1
  return amis_communs

def algo2(tableau):
  n = len(tableau)
  amis_communs = [
    [0 for i in range(n)]
    for i in range(n)]
  for k in range(n):
    for i in range(n):
      if tableau[k][i]==1:
        for j in range(n):
          if (i!=j and
          tableau[k][j]==1):
            amis_communs[i][j] += 1
  return amis_communs

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.