Page 1 sur 1

PGCD - Algorithme d'Euclide

Posté : jeu. 8 nov. 2012, 12:00
par GM

Figure asymptote 0a4f585e5a24d457268b950b41904768
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***

CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
  1. unitsize(2cm);
  2.  
  3. void pgcd(picture pic=currentpicture, int a, int b, pair A=(0,0), pair d=0){
  4. picture p;
  5. int k=0, a_=abs(a), b_=abs(b), r=a_;
  6. real y=0;
  7. while (r>0)
  8. {
  9. r=a_%b_;
  10. frame f;
  11. label(f,string(a_),(0,y),2W,basealign);
  12. label(f,"=",(0,y),basealign);
  13. label(f,string(b_)+"$\times$"+string(floor(a_/b_))+"+"+string(r),(0,y),2E,basealign);
  14. y -= size(f).y;
  15. a_=b_;
  16. b_=r;
  17. add(p,f);
  18. }
  19. label(p,format("\fbox{pgcd(%i",a)
  20. +format(";%i)=",b)
  21. +format("%i}",a_),truepoint(p,S),2S,red+basealign);
  22. add(pic,p.fit(),A,d);
  23. }
  24. real e=5;
  25. pgcd(1015,717,d=e*NW);
  26. pgcd(1015,716,d=e*NE);
  27. pgcd(1015,715,d=e*SW);
  28. pgcd(1015,714,d=e*SE);

Re: PGCD - Algorithme d'Euclide

Posté : jeu. 8 nov. 2012, 12:13
par GM

Figure asymptote 2cabd084daf5ee5bb853cffea7761b68
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***

CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
  1. unitsize(1cm);
  2.  
  3. void pgcd(picture pic=currentpicture, int a, int b, pair A=(0,0), pair d=0){
  4. picture p;
  5. int a_=abs(a), b_=abs(b), r=a_;
  6. pen[] stylo={red,blue,green,.7pink,.5yellow}; stylo.cyclic=true;
  7. int k=0;
  8. while (r>0)
  9. {
  10. frame f;
  11. r=a_%b_;
  12. label(f,string(a_),(0,0),2NW,stylo[k-1]);
  13. label(f,string(b_),(0,0),2NE,stylo[k]);
  14. label(f,string(r),(0,0),2SW,stylo[k+1]);
  15. label(f,string(floor(a_/b_)),(0,0),2SE);
  16. draw(f,(0,max(f).y)--(0,min(f).y)^^(0,0)--(max(f).x,0));
  17. a_=b_;
  18. b_=r;
  19. add(p, f, truepoint(p, E),5E);
  20. ++k;
  21. }
  22. label(p,format("\fbox{Le PGCD est le dernier reste non nul, \`a savoir : %i.}",a_),truepoint(p,S),2S,blue);
  23. add(pic,p.fit(),A,d);
  24. }
  25. real e=15;
  26. pgcd(1025,715,d=e*N);
  27. pgcd(1025,719,d=e*S);