{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": { "editable": true, "slideshow": { "slide_type": "slide" }, "tags": [] }, "source": [ "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.dsi.universite-paris-saclay.fr%2Fbruno.denis%2Fintro_jupyter/HEAD?labpath=notebooks%2Flabyrinthe.ipynb)\n", "[![NbViewer](https://badgen.net/static/render/NbViewer/orange)](https://nbviewer.org/urls/gitlab.dsi.universite-paris-saclay.fr/bruno.denis/intro_jupyter/-/raw/main/notebooks/labyrinthe.ipynb)\n", "\n", "# Labyrinthe\n", "\n", "Ce carnet Jupyter est un exemple d'utilisation pour l'apprentissage au codage avec le langage Python. L'apprenant doit résoudre des énigmes en guidant une fourmi perdue dans des labyrinthes parsemés d'obstacles (pierres, toiles d'araigné). Le module `laby` (https://github.com/nthiery/laby-jupyter) est développé par des collègues de l'Univiversité de Paris-Saclay (Nicolas Thiéry et al.)\n", "\n", "Les fonctionnalités majeures de ce carnet sont :\n", "- **Interactivité** par utilisation du module `ipywidgets` utilisé par le module `laby` \n", "- **codage** par utilisation du module `ipywidgets` utilisé par le module `laby` \n", "\n", "![Labyrinthes](../assets/img/labyrinthes.png)" ] }, { "cell_type": "markdown", "id": "1", "metadata": { "editable": true, "slideshow": { "slide_type": "slide" }, "tags": [] }, "source": [ "## Problème 1" ] }, { "cell_type": "code", "execution_count": 1, "id": "2", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8006b6b97289447881a045d079762043", "version_major": 2, "version_minor": 0 }, "text/plain": [ "LabyPlayer(children=(View(children=(Image(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x00 \\x00\\x00\\x00…" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from laby.global_fr import *\n", "Laby(niveau=\"1a\") # charge un labyrinthe de la bibliothèque" ] }, { "cell_type": "code", "execution_count": 2, "id": "3", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "# Une solution pour la fourmi de sortir\n", "droite() # Fait pivoter la fourmi vers la droite\n", "avance() ; avance() ; avance() # Trois pas en avant\n", "gauche() # Fait pivoter la fourmi vers la gauche\n", "avance() ; avance() # Deux pas en avant\n", "ouvre() # Ouverture de la sortie" ] }, { "cell_type": "markdown", "id": "4", "metadata": { "editable": true, "slideshow": { "slide_type": "slide" }, "tags": [] }, "source": [ "## Problème 2" ] }, { "cell_type": "code", "execution_count": 3, "id": "5", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "from laby.global_fr import *" ] }, { "cell_type": "code", "execution_count": 4, "id": "6", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e416eb466b1d4d458b9a17d9cd7a3ed5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "LabyPlayer(children=(View(children=(Image(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x00 \\x00\\x00\\x00…" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Laby(lignes = 3, colonnes = 5)" ] }, { "cell_type": "code", "execution_count": 5, "id": "7", "metadata": { "editable": true, "slideshow": { "slide_type": "subslide" }, "tags": [] }, "outputs": [], "source": [ "def sort():\n", " gauche()\n", " r = regarde()\n", " while r!= Sortie:\n", " while r != Vide and r!= Sortie:\n", " droite()\n", " r = regarde()\n", " if r == Vide:\n", " avance()\n", " gauche()\n", " r = regarde()\n", " ouvre()" ] }, { "cell_type": "code", "execution_count": 6, "id": "8", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "sort()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }