Skip to content

Commit

Permalink
added problem 17 in py
Browse files Browse the repository at this point in the history
  • Loading branch information
ditekunov authored May 26, 2018
1 parent 3e07f04 commit bcb8060
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions python/Problem_17.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"### Problem 17: Number letter counts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I'm not very keen on char-dependent tasks, so I'll try to implement the task obviosly:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"21124\nTook 0.0037851333618164062\n"
]
}
],
"source": [
"import time\n",
" \n",
"start = time.time()\n",
" \n",
"S = [0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8]\n",
"D = [0,3,6,6,5,5,5,7,6,6]\n",
"H = 7\n",
"T = 8\n",
" \n",
"total = 0\n",
"for i in range(1,1000):\n",
" c = i % 10 \n",
" b = ((i % 100) - c) / 10 \n",
" a = ((i % 1000) - (b * 10) - c) / 100 \n",
" \n",
" if a != 0:\n",
" total += S[int(a)] + H \n",
" if b != 0 or c != 0: total += 3 \n",
" if b == 0 or b == 1: total += S[int(b * 10 + c)]\n",
" else: total += D[int(b)] + S[c]\n",
" \n",
"total += S[1] + T\n",
"finish = time.time() - start\n",
" \n",
"print(total)\n",
"\n",
"print(\"Took \", finish)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we'll not think about number of letters/days/etc and simply take the range, than the complexity is O(N)."
]
}
],
"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 bcb8060

Please sign in to comment.