{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def pgcd_sous(a,b,appel = 0):\n", " if a == b:\n", " print(\"Nombre d'appels: \", appel+1)\n", " return a\n", " else:\n", " A = max(a,b)\n", " B = min(a,b)\n", " return pgcd_sous(A-B, B, appel = appel + 1)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Nombre d'appels: 5\n" ] }, { "data": { "text/plain": [ "28" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pgcd_sous(224, 84)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "16.0" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "224/14" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "6.0" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "84/14" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Nombre d'appels: 5\n" ] }, { "data": { "text/plain": [ "32" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pgcd_sous(224,96)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "6.0" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "96/16" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "14.0" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "224/16" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }