From bcb80600b774fe9f1fe063ad8fe1bc1c8fc14ef8 Mon Sep 17 00:00:00 2001 From: Tekunov Daniil Date: Sat, 26 May 2018 21:25:12 +0300 Subject: [PATCH] added problem 17 in py --- python/Problem_17.ipynb | 91 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 python/Problem_17.ipynb diff --git a/python/Problem_17.ipynb b/python/Problem_17.ipynb new file mode 100644 index 0000000..dd70fca --- /dev/null +++ b/python/Problem_17.ipynb @@ -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 +} \ No newline at end of file