• Aucun résultat trouvé

sentinelle resultat, constant_depuis = 0, 0 for j in range(1, len(a

N/A
N/A
Protected

Academic year: 2022

Partager "sentinelle resultat, constant_depuis = 0, 0 for j in range(1, len(a"

Copied!
2
0
0

Texte intégral

(1)

import random as rd n = 10

a = [rd.randint(0,4) for k in range(n)]

s, t = 0, [0]

for k in range(1, n):

s += rd.randint(1, 2) t.append(s)

print('a : ', a) print('t : ', t)

# Q1

def compte(x, a):

nombre = 0 for elt in a:

if elt == x:

nombre += 1 return nombre

# Q1 bis

def compte_bis(x, a):

return len([u for u in a if u == x])

# Q2

def occurrences(a):

return [compte(a[i], a) for i in range(len(a))]

# Q3

def maxconstant(a):

a.append(-2) # sentinelle resultat, constant_depuis = 0, 0

for j in range(1, len(a)):

if a[j] != a[j-1]:

resultat_courant = t[j-1] - t[constant_depuis]

if resultat_courant > resultat:

resultat = resultat_courant constant_depuis = j

a.pop()

return resultat

print('maxconstant(a) : ', maxconstant(a))

1

(2)

# Q4

def maxocurrences(a, occ):

i1, i2 = 0, -1

for j in range(1, len(a)):

if occ[j] > occ[i1]:

i1, i2 = j, i1

if (i2 == -1 or occ[j] > occ[i2]) and a[j] !=

a[i1]:

i2 = j return i1, i2

# Q5

def trier(a, m1, m2):

n = len(a)

d2, d3, d4 = 0, 0, n while d3 < d4:

if a[d3] == m1:

a[d2], a[d3] = a[d3], a[d2]

d2 += 1 d3 += 1 else:

if a[d3] == m2:

d3 += 1 else:

a[d4 - 1], a[d3] = a[d3], a[d4 - 1]

d4 -= 1

# Q6 : non

occ = occurrences(a)

i1, i2 = maxocurrences(a, occ) print('i1, i2 : ', i1, i2) m1, m2 = a[i1], a[i2]

print('m1, m2 : ', m1, m2)

trier(a, m1, m2) print(a)

2

Références

Documents relatifs

Noussommespersuadés quel'utilisation de normescommunes faciliteledéveloppement de logicielcalculateuret ie rendeplustransparent.Ellesaccélèrent égalementles

This non-negative functional tF was shown to be lower semi-continuous on the set of Lipschitz functions with the 1: I topology and hence could be extended to

Si nous nous reportons aux r~sultats contenus dans notre travail relatif aux formes quadrilin6aires, nous verrons ais~ment que la condition A -~ o, entraine

Moti- vated by this observation we shall discuss the notion of an approximate limit in Section 6 and prove that a function satisfying the uniform Harnack

celui-ci descend dans un espace longiligne en double hauteur aménagé entre l’enveloppe de l’habitation et la paroi intérieure du voile de façade, qui constitue également le mur

• Cette équation étant valable pour tout régime sinusoïdal, elle est aussi valable pour tout régime variable ; on peut par précaution vérifier que le régime

parfaits fonc- tionnant en régime linéaire. L'ensemble, inséré dans un circuit par l'intermédiaire des deux bornes A et B, se comporte comme un dipôle soumis à une tension

Déterminer la valeur moyenne de la puissance transportée par