#!/bin/python3

from random import randint
from math   import log
import matplotlib.pyplot as plt

import argument as arg

def   euclide( a, b  ) :
   nbi = 0
   while  b > 0 :
      r = a % b
      a = b
      b = r
      nbi+= 1
   return nbi

arg.cmdline()

print( 'r=', arg.repetition, 'i=',arg.iteration )
x = []
y = []
z = []
f = []
p = []

for n in  range(2 , arg.iteration  ) :
	cpt = 0
	for  r in range( arg.repetition  ) :
		a = n
		b = randint(0, n)
		nbi =  euclide( a, b ) 
		if r == 0 :
			min = nbi
			max = nbi
		cpt += nbi
		if nbi > max :
			max = nbi
		if nbi < min :
			min = nbi
	x.append( n )
	z.append( log(n)   )
	y.append( cpt / arg.repetition )
	f.append(  min  )
	p.append(  max   )

plt.title("Analyse de l'algorithme d'Euclide")
plt.ylabel('itération')
plt.xlabel('a')
plt.plot(x, y)
plt.plot(x, z)
plt.plot(x, p)
plt.plot(x, f)
plt.show()
plt.close()


