{ "metadata": { "name": "", "signature": "sha256:3bee186dc07a3ca04c411bfe4afddb2825c4dfdf62d23e25027b08ed1ec6281b" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Given two words, print the steps in turning one word into the other, or a message that it is not possible." ] }, { "cell_type": "code", "collapsed": false, "input": [ "def transmute(word1, word2):\n", " if len(word1) != len(word2):\n", " print \"Transmutation impossible\"\n", " " ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "transmute(\"word\", \"otherword\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Transmutation impossible\n" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "def transmute(word1, word2):\n", " word3 = list(word1);\n", " if len(word1) == len(word2):\n", " for i in xrange(len(word2)):\n", " for j in word1:\n", " if word2[i] is j:\n", " word3.remove(word2[i])\n", " word3.insert(i, word2[i])\n", " print ''.join(word3)\n", " if ''.join(word3) != word2:\n", " print \"Transmutation impossible\"\n", " else:\n", " print \"Transmutation impossible\"\n", " \n", " " ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 38 }, { "cell_type": "code", "collapsed": false, "input": [ "transmute(\"door\", \"rood\")\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "rdoo\n", "rodo\n", "rodo\n", "rdoo\n", "rdoo\n", "rood\n" ] } ], "prompt_number": 39 }, { "cell_type": "code", "collapsed": false, "input": [ "transmute(\"door\", \"dorr\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "door\n", "door\n", "door\n", "doro\n", "door\n", "Transmutation impossible\n" ] } ], "prompt_number": 40 }, { "cell_type": "code", "collapsed": false, "input": [ "transmute(\"kitchen\", \"thicken\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "tkichen\n", "thkicen\n", "thikcen\n", "thicken\n", "thicken\n", "thicken\n", "thicken\n" ] } ], "prompt_number": 41 }, { "cell_type": "code", "collapsed": false, "input": [ "transmute(\"thicken\", \"kitchen\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "kthicen\n", "kithcen\n", "kithcen\n", "kitchen\n", "kitchen\n", "kitchen\n", "kitchen\n" ] } ], "prompt_number": 42 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }