Skip to content

Commit

Permalink
Added p16 in py
Browse files Browse the repository at this point in the history
  • Loading branch information
ditekunov authored May 26, 2018
1 parent 34fe3a0 commit d15b1f5
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions python/Problem_16.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"### Problem 16: Power digit sum"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The solution is obvious and simple:"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1366\nTime: 0.0004570484161376953\n"
]
}
],
"source": [
"import time\n",
"\n",
"start = time.time()\n",
"\n",
"p = list(str(pow(2,1000)))\n",
"print(sum([int(i) for i in p]))\n",
"\n",
"finish = time.time() - start\n",
"\n",
"print(\"Time: \", finish)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As Python's pow() function is realized as a fast power, its asymptotic is O(log(N)) and is already best for this task."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit d15b1f5

Please sign in to comment.