From 52466839de5496658a452f1a9a602b9c810af2d1 Mon Sep 17 00:00:00 2001 From: Suwako Moriya Date: Thu, 12 Dec 2019 08:50:47 +0000 Subject: [PATCH] =?UTF-8?q?[TP4]=20Question=204=20pr=C3=A9sum=C3=A9e=20fin?= =?UTF-8?q?ie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TP4/main.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/TP4/main.py b/TP4/main.py index b3dba42..49000e9 100644 --- a/TP4/main.py +++ b/TP4/main.py @@ -32,7 +32,9 @@ def frequences(t0): # 6: def graphe_frequences(t0): - plt.plot(list(range(1, 27)), frequences(t0), 'ro') + #plt.plot(list(range(1, 27)), frequences(t0), 'ro') + for i, j in enumerate(t0): + plt.bar(i+1, j) plt.ylabel('fréquences') plt.xlabel('lettres') plt.show() @@ -76,3 +78,19 @@ def pgcd(a, b): return a # 4: + +def pgcdDesDistancesEntreRepetitions(l, i): + ecarts=[] + sec=l[i:i+3] + g=i + for j in range(g+1, len(l)-2): + if sec==l[j:j+3]: + ecarts.append(j-g) + g=j + print(ecarts) + while len(ecarts)>1: + ecarts[0]=pgcd(ecarts.pop(0), ecarts[0]) + if ecarts: + return ecarts[0] + return 0 + \ No newline at end of file