From f63b42c9e627ef1fff979554213757ccb6f20f93 Mon Sep 17 00:00:00 2001
From: JorgeEMalambo <jorge_malambo@yahoo.com>
Date: Fri, 5 Feb 2021 17:39:11 -0500
Subject: [PATCH] primera parte lista

---
 ejercicio2.ipynb | 171 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 169 insertions(+), 2 deletions(-)

diff --git a/ejercicio2.ipynb b/ejercicio2.ipynb
index 8bcff0f..2c793f1 100644
--- a/ejercicio2.ipynb
+++ b/ejercicio2.ipynb
@@ -10,9 +10,18 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": 3
+   "version": "3.9.0-final"
   },
-  "orig_nbformat": 2
+  "orig_nbformat": 2,
+  "kernelspec": {
+   "name": "python3",
+   "display_name": "Python 3.9.0 64-bit",
+   "metadata": {
+    "interpreter": {
+     "hash": "7812ea015bdcee6f23a998adcdd2ef97c151c0c241b7b7070987d9313e41299d"
+    }
+   }
+  }
  },
  "nbformat": 4,
  "nbformat_minor": 2,
@@ -27,6 +36,164 @@
    "cell_type": "markdown",
    "metadata": {}
   },
+  {
+   "cell_type": "code",
+   "execution_count": 23,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "from math import comb\n",
+    "def linePascal(n):\n",
+    "\n",
+    "    return [comb(n,x) for x in range(n+1)]"
+   ]
+  },
+  {
+   "source": [
+    "El modulo $math$, tiene un metodo llamado $comb$, el cual resuelve la combinatoria $C_{n}^{p}=\\binom{n}{m}=\\frac{n!}{p!(n-p)!}$ y dado que cada elemento de la fila se compone por la suma $(a+b)^n=\\sum_{m=0}^{n}\\binom{n}{m}a^{n-k}b^{n-k}$, los coeficientes binomoales se almacenaran en una lista que retornara la funcion definida\n"
+   ],
+   "cell_type": "markdown",
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 24,
+   "metadata": {},
+   "outputs": [
+    {
+     "output_type": "stream",
+     "name": "stdout",
+     "text": [
+      "[1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1]\n"
+     ]
+    }
+   ],
+   "source": [
+    "print(linePascal(10))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "Por otra parte debemos estar seguros que el imput sea un entero positivo para poder calcular los coeficientes binomiales con la formula anterior, asi que debemos incluir lienas de codigo para la validación"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 46,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def linePascal(n):\n",
+    "    if type(n) is not int:\n",
+    "        print (f'el valor enviado \\'{n}\\', no es un entero')\n",
+    "        return []\n",
+    "    elif n<0:\n",
+    "        print (f'el valor enviado \\'{n}\\', no es un entero positivo')\n",
+    "        return []\n",
+    "    return [comb(n,x) for x in range(n+1)]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 47,
+   "metadata": {},
+   "outputs": [
+    {
+     "output_type": "stream",
+     "name": "stdout",
+     "text": [
+      "el valor enviado '-12', no es un entero positivo\n"
+     ]
+    },
+    {
+     "output_type": "execute_result",
+     "data": {
+      "text/plain": [
+       "[]"
+      ]
+     },
+     "metadata": {},
+     "execution_count": 47
+    }
+   ],
+   "source": [
+    "linePascal(-12)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def pascal(orden, matriz=None):\n",
+    "    if matriz is None: matriz = [[1]]\n",
+    "    if orden == 1:\n",
+    "        return matriz\n",
+    "        prev_row = matriz[-1]\n",
+    "        new_row = [1] + [sum(i) for i in zip(prev_row, prev_row[1:])] + [1]\n",
+    "        return triangle(orden - 1, matriz + [new_row])\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [
+    {
+     "output_type": "execute_result",
+     "data": {
+      "text/plain": [
+       "[[1],\n",
+       " [1, 1],\n",
+       " [1, 2, 1],\n",
+       " [1, 3, 3, 1],\n",
+       " [1, 4, 6, 4, 1],\n",
+       " [1, 5, 10, 10, 5, 1],\n",
+       " [1, 6, 15, 20, 15, 6, 1]]"
+      ]
+     },
+     "metadata": {},
+     "execution_count": 7
+    }
+   ],
+   "source": [
+    "triangle(7)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [
+    {
+     "output_type": "stream",
+     "text": [
+      "\u001b[0;31mInit signature:\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m/\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+      "\u001b[0;31mDocstring:\u001b[0m     \n",
+      "zip(*iterables) --> A zip object yielding tuples until an input is exhausted.\n",
+      "\n",
+      "   >>> list(zip('abcdefg', range(3), range(4)))\n",
+      "   [('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]\n",
+      "\n",
+      "The zip object yields n-length tuples, where n is the number of iterables\n",
+      "passed as positional arguments to zip().  The i-th element in every tuple\n",
+      "comes from the i-th iterable argument to zip().  This continues until the\n",
+      "shortest argument is exhausted.\n",
+      "\u001b[0;31mType:\u001b[0m           type\n",
+      "\u001b[0;31mSubclasses:\u001b[0m     \n"
+     ],
+     "name": "stdout"
+    }
+   ],
+   "source": [
+    "zip?\n"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
-- 
GitLab