{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "0320_permutaciones.ipynb", "provenance": [], "authorship_tag": "ABX9TyNB1MbWlX+3N35dVFoX8jD/", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "source": [ "# Permutaciones\n", "Permite saber de cuantas formas distintas es posible reordenar n elementos.\n", "\n", "Ejemplos:\n", "* Disponemos de 5 letras: \"ABCDE\".\n", " - Existen 120 formas de reordenar las 4 letras.\n", " - $5! = 5 * 4 * 3 * 2 * 1 = 120$\n", "* Disponemos de 4 libros en una estanterĂ­a, cada libro tiene la tapa de un color: \"Rojo, Verde, Azul, Naranja\" = \"RVAN\"\n", " - Existen 24 formas de reordenar los 4 libros en la estanterĂ­a.\n", " - $4! = 4 * 3 * 2 * 1 = 24$" ], "metadata": { "id": "Vuobr8Jkn4Wx" } }, { "cell_type": "code", "source": [ "from itertools import permutations\n", "\n", "# Definir las letras\n", "letras = \"ABCDE\"\n", "\n", "# Generar permutaciones de 5 letras\n", "permutaciones = permutations(letras, 5)\n", "\n", "# Iterar y mostrar las permutaciones\n", "for permutacion in permutaciones:\n", " print(''.join(permutacion))" ], "metadata": { "id": "Aq2YY3zmONGK", "outputId": "0185dbd7-72db-44c3-94fe-6443a35c8c69", "colab": { "base_uri": "https://localhost:8080/" } }, "execution_count": 2, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "ABCDE\n", "ABCED\n", "ABDCE\n", "ABDEC\n", "ABECD\n", "ABEDC\n", "ACBDE\n", "ACBED\n", "ACDBE\n", "ACDEB\n", "ACEBD\n", "ACEDB\n", "ADBCE\n", "ADBEC\n", "ADCBE\n", "ADCEB\n", "ADEBC\n", "ADECB\n", "AEBCD\n", "AEBDC\n", "AECBD\n", "AECDB\n", "AEDBC\n", "AEDCB\n", "BACDE\n", "BACED\n", "BADCE\n", "BADEC\n", "BAECD\n", "BAEDC\n", "BCADE\n", "BCAED\n", "BCDAE\n", "BCDEA\n", "BCEAD\n", "BCEDA\n", "BDACE\n", "BDAEC\n", "BDCAE\n", "BDCEA\n", "BDEAC\n", "BDECA\n", "BEACD\n", "BEADC\n", "BECAD\n", "BECDA\n", "BEDAC\n", "BEDCA\n", "CABDE\n", "CABED\n", "CADBE\n", "CADEB\n", "CAEBD\n", "CAEDB\n", "CBADE\n", "CBAED\n", "CBDAE\n", "CBDEA\n", "CBEAD\n", "CBEDA\n", "CDABE\n", "CDAEB\n", "CDBAE\n", "CDBEA\n", "CDEAB\n", "CDEBA\n", "CEABD\n", "CEADB\n", "CEBAD\n", "CEBDA\n", "CEDAB\n", "CEDBA\n", "DABCE\n", "DABEC\n", "DACBE\n", "DACEB\n", "DAEBC\n", "DAECB\n", "DBACE\n", "DBAEC\n", "DBCAE\n", "DBCEA\n", "DBEAC\n", "DBECA\n", "DCABE\n", "DCAEB\n", "DCBAE\n", "DCBEA\n", "DCEAB\n", "DCEBA\n", "DEABC\n", "DEACB\n", "DEBAC\n", "DEBCA\n", "DECAB\n", "DECBA\n", "EABCD\n", "EABDC\n", "EACBD\n", "EACDB\n", "EADBC\n", "EADCB\n", "EBACD\n", "EBADC\n", "EBCAD\n", "EBCDA\n", "EBDAC\n", "EBDCA\n", "ECABD\n", "ECADB\n", "ECBAD\n", "ECBDA\n", "ECDAB\n", "ECDBA\n", "EDABC\n", "EDACB\n", "EDBAC\n", "EDBCA\n", "EDCAB\n", "EDCBA\n" ] } ] } ] }