Drafted solution for 53 and 54. I will have to validate.

This commit is contained in:
2018-12-24 16:13:21 -05:00
parent 3eca2e83c2
commit 4acfe89f92
2 changed files with 253 additions and 0 deletions

View File

@@ -30,6 +30,58 @@
"How many, not necessarily distinct, values of nCr, for 1 ≤ n ≤ 100, are greater than one-million?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import math\n",
"\n",
"def combinations_naiv(n, r):\n",
" return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))\n",
"\n",
"assert(combinations_naiv(5, 3) == 10)\n",
"assert(combinations_naiv(23, 10) == 1144066)\n",
"assert(combinations_naiv(20, 20) == 1)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"count = 0\n",
"\n",
"for n in range (1, 101):\n",
" for r in range(1, n + 1):\n",
" if combinations_naiv(n, r) > 10**6:\n",
" count += 1\n",
"\n",
"s = count"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4075\n"
]
}
],
"source": [
"print(s)\n",
"assert(s == 4075)"
]
},
{
"cell_type": "code",
"execution_count": null,