def iota (n): # fonction qui fait une liste de taille n-1 (n est un entier) tab = [] for i in range(n): tab.append(i) return (tab) def contient (tab, n): # fonction qui cherche si l'entier n est dedans for i in range (len(tab)): if tab[i] == n: return True return False print (contient) def ajouter (tab, x): # valeur a rajouter if tab == []: return [x] else: for i in range (len(tab)): if contient(tab, x) == False: tab.append(x) return tab def retirer (tab, x): for i in range (len(tab)): if contient(tab, x) == True: tab.remove(x) return tab def voisins(x, y, nX, nY): N = x + y * nX - nX O = x + y * nX - 1 S = x + y * nX + nX E = x + y * nX + 1 if x == 0 and y == 0: # coin gauche haut voisin = [S, E] elif x == (nX - 1) and y == 0: # coin droite haut voisin = [O, S] elif x == 0 and y == (nY - 1): # coin gauche bas voisin = [N, E] elif x == (nX - 1) and y == (nY - 1): # coin droite bas voisin = [N, O] elif y == 0 and (x != 0 or x != (nX - 1)): # premiere rangee voisin = [O, S, E] elif x == 0 and (y != 0 or y != (nY - 1)): # premiere colonne voisin = [N, S, E] elif y == (nY-1) and (x != 0 or x != nX - 1): # derniere rangee voisin = [N, O, E] elif x == (nX-1) and (y != 0 or y != nY - 1): # derniere colonne voisin = [N, O, S] else: # le reste voisin = [N, O, S, E] return voisin def testFinaux(): assert iota(0) == [], 'tableau vide' assert iota(5) == [0,1,2,3,4] assert iota(10) == [0,1,2,3,4,5,6,7,8,9] assert iota(15) == [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] assert iota(22) ==[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21] assert contient([], 0) == False assert contient([100,1], 10) == False assert contient([1,2,3,4,5], 5) == True assert contient([5,5,5,5,5], 5) == True assert contient ([],10) == False assert ajouter([], 4) == [4] assert ajouter([9,2,5], 4) == [9,2,5,4] assert ajouter([9,2,5], 2) == [9,2,5] assert ajouter([20,5], 2) == [20,5,2] assert ajouter([7,8], 0) == [7,8,0] assert ajouter([0], 0) == [0] assert ajouter([0], 1) == [0,1] assert retirer([9,2,5], 2) == [9,5] assert retirer([9,2,5], 4) == [9,2,5] assert retirer([], 2) == [] assert retirer([2], 2) == [] assert retirer([1,1,6], 1) == [6] assert voisins (2,1,8,4) == [2, 9, 18, 11] assert voisins (5,2,8,4) == [13, 20, 29, 22] assert voisins (0,0,8,4) == [8, 1] assert voisins (7,3,8,4) == [23, 30] assert voisins (7,0,8,4) == [6, 15] assert voisins (0,3,8,4) == [16, 25] assert voisins (3,0,8,4) == [2, 11, 4] assert voisins (0,1,8,4) == [0, 16, 9] assert voisins (3,3,8,4) == [19, 26, 28] assert voisins (7,2,8,4) == [15, 22, 31] testFinaux()