X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=08-word-chains%2Fexplore-word-chain-4.ipynb;h=5449951bf02476cc6fbebe11cb07a34d507e683f;hb=881b1889a51e7a0ea314b59234c477e0849c0427;hp=da9196ad34d3e3269db135f8df7d4a1045d5b21d;hpb=f8a31f9a1391dbafc69ea6042dd213a3baa7a64c;p=ou-summer-of-code-2017.git diff --git a/08-word-chains/explore-word-chain-4.ipynb b/08-word-chains/explore-word-chain-4.ipynb index da9196a..5449951 100644 --- a/08-word-chains/explore-word-chain-4.ipynb +++ b/08-word-chains/explore-word-chain-4.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -16,10 +16,8 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, + "execution_count": 2, + "metadata": {}, "outputs": [ { "data": { @@ -27,22 +25,20 @@ "2336" ] }, - "execution_count": 5, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "words = [w.strip() for w in open('08-offices.txt').readlines()]\n", + "words = [w.strip() for w in open('08-rooms.txt').readlines()]\n", "len(words)" ] }, { "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": false - }, + "execution_count": 3, + "metadata": {}, "outputs": [ { "data": { @@ -59,7 +55,7 @@ " 'achy']" ] }, - "execution_count": 6, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -70,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": { "collapsed": true }, @@ -87,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": { "collapsed": true }, @@ -102,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "metadata": { "collapsed": true }, @@ -114,10 +110,8 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": { - "collapsed": false - }, + "execution_count": 7, + "metadata": {}, "outputs": [ { "data": { @@ -125,7 +119,7 @@ "['able']" ] }, - "execution_count": 10, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -136,10 +130,8 @@ }, { "cell_type": "code", - "execution_count": 11, - "metadata": { - "collapsed": false - }, + "execution_count": 8, + "metadata": {}, "outputs": [ { "data": { @@ -147,7 +139,7 @@ "['axle', 'abbe', 'ably']" ] }, - "execution_count": 11, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -158,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": { "collapsed": true }, @@ -171,10 +163,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": false - }, + "execution_count": 10, + "metadata": {}, "outputs": [ { "data": { @@ -182,7 +172,7 @@ "0" ] }, - "execution_count": 13, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -193,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "metadata": { "collapsed": true }, @@ -210,10 +200,8 @@ }, { "cell_type": "code", - "execution_count": 15, - "metadata": { - "collapsed": false - }, + "execution_count": 12, + "metadata": {}, "outputs": [ { "data": { @@ -221,7 +209,7 @@ "[['abbe', 'able']]" ] }, - "execution_count": 15, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -232,10 +220,8 @@ }, { "cell_type": "code", - "execution_count": 16, - "metadata": { - "collapsed": false - }, + "execution_count": 13, + "metadata": {}, "outputs": [ { "data": { @@ -243,7 +229,7 @@ "[['abbe', 'able', 'axle'], ['abbe', 'able', 'ably']]" ] }, - "execution_count": 16, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -254,10 +240,8 @@ }, { "cell_type": "code", - "execution_count": 17, - "metadata": { - "collapsed": false - }, + "execution_count": 14, + "metadata": {}, "outputs": [ { "data": { @@ -265,7 +249,7 @@ "[['abbe', 'able', 'ably', 'ally']]" ] }, - "execution_count": 17, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -276,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "metadata": { "collapsed": true }, @@ -294,7 +278,7 @@ " else:\n", " successors = extend(current)\n", " agenda = agenda[1:] + successors\n", - " if agenda:\n", + " if finished:\n", " return current\n", " else:\n", " return None " @@ -302,7 +286,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 16, "metadata": { "collapsed": true }, @@ -322,7 +306,7 @@ " closed.add(current[-1])\n", " successors = extend(current, closed)\n", " agenda = agenda[1:] + successors\n", - " if agenda:\n", + " if finished:\n", " return current\n", " else:\n", " return None " @@ -330,10 +314,8 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": { - "collapsed": false - }, + "execution_count": 17, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -352,7 +334,7 @@ "['abbe', 'able', 'ably', 'ally']" ] }, - "execution_count": 20, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -363,7 +345,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "metadata": { "collapsed": true }, @@ -381,7 +363,7 @@ " else:\n", " successors = extend(current)\n", " agenda = successors + agenda[1:]\n", - " if agenda:\n", + " if finished:\n", " return current\n", " else:\n", " return None " @@ -389,10 +371,8 @@ }, { "cell_type": "code", - "execution_count": 22, - "metadata": { - "collapsed": false - }, + "execution_count": 19, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -411,7 +391,7 @@ "['abbe', 'able', 'ably', 'ally']" ] }, - "execution_count": 22, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -422,10 +402,8 @@ }, { "cell_type": "code", - "execution_count": 23, - "metadata": { - "collapsed": false - }, + "execution_count": 20, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -942,7 +920,13 @@ "['cart', 'mart', 'mare', 'mire']\n", "['cart', 'mart', 'mare', 'more']\n", "['cart', 'mart', 'mare', 'mace']\n", - "['cart', 'mart', 'mare', 'made']\n", + "['cart', 'mart', 'mare', 'made']\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "['cart', 'mart', 'mare', 'make']\n", "['cart', 'mart', 'mare', 'male']\n", "['cart', 'mart', 'mare', 'mane']\n", @@ -1502,7 +1486,13 @@ "['cart', 'cant', 'rant', 'raft']\n", "['cart', 'cant', 'rant', 'rapt']\n", "['cart', 'cant', 'rant', 'rang']\n", - "['cart', 'cant', 'rant', 'rank']\n", + "['cart', 'cant', 'rant', 'rank']\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "['cart', 'cant', 'want', 'pant']\n", "['cart', 'cant', 'want', 'rant']\n", "['cart', 'cant', 'want', 'went']\n", @@ -1567,7 +1557,7 @@ "['cart', 'cant', 'cans', 'vans']" ] }, - "execution_count": 23, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -1578,10 +1568,8 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": { - "collapsed": false - }, + "execution_count": 21, + "metadata": {}, "outputs": [ { "data": { @@ -1589,7 +1577,7 @@ "['cart', 'cant', 'cane', 'vane']" ] }, - "execution_count": 24, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -1600,10 +1588,8 @@ }, { "cell_type": "code", - "execution_count": 25, - "metadata": { - "collapsed": false - }, + "execution_count": 22, + "metadata": {}, "outputs": [ { "data": { @@ -2188,7 +2174,7 @@ " 'vane']" ] }, - "execution_count": 25, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -2199,7 +2185,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 23, "metadata": { "collapsed": true }, @@ -2219,7 +2205,7 @@ " successors = extend(current)\n", " for s in successors:\n", " heapq.heappush(agenda, (len(current) + distance(s[-1], goal) - 1, s))\n", - " if agenda:\n", + " if finished:\n", " return current\n", " else:\n", " return None " @@ -2227,10 +2213,8 @@ }, { "cell_type": "code", - "execution_count": 27, - "metadata": { - "collapsed": false - }, + "execution_count": 24, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -2248,7 +2232,7 @@ "['cart', 'cant', 'cane', 'vane']" ] }, - "execution_count": 27, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -2259,7 +2243,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 81, "metadata": { "collapsed": true }, @@ -2281,7 +2265,7 @@ " successors = extend(current, closed)\n", " for s in successors:\n", " heapq.heappush(agenda, (len(current) + distance(s[-1], goal) - 1, s))\n", - " if agenda:\n", + " if finished:\n", " return current\n", " else:\n", " return None " @@ -2289,10 +2273,8 @@ }, { "cell_type": "code", - "execution_count": 29, - "metadata": { - "collapsed": false - }, + "execution_count": 26, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -2310,7 +2292,7 @@ "['cart', 'cant', 'cane', 'vane']" ] }, - "execution_count": 29, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -2330,10 +2312,8 @@ }, { "cell_type": "code", - "execution_count": 30, - "metadata": { - "collapsed": false - }, + "execution_count": 27, + "metadata": {}, "outputs": [ { "data": { @@ -2341,7 +2321,7 @@ "94" ] }, - "execution_count": 30, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -2367,10 +2347,8 @@ }, { "cell_type": "code", - "execution_count": 31, - "metadata": { - "collapsed": false - }, + "execution_count": 28, + "metadata": {}, "outputs": [ { "data": { @@ -2378,7 +2356,7 @@ "2204" ] }, - "execution_count": 31, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -2389,10 +2367,8 @@ }, { "cell_type": "code", - "execution_count": 32, - "metadata": { - "collapsed": false - }, + "execution_count": 29, + "metadata": {}, "outputs": [ { "data": { @@ -2400,7 +2376,7 @@ "1" ] }, - "execution_count": 32, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -2411,9 +2387,8 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 30, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [ @@ -2423,7 +2398,7 @@ "Counter({1: 75, 2: 6, 3: 7, 4: 2, 5: 2, 6: 1, 2204: 1})" ] }, - "execution_count": 33, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -2434,10 +2409,8 @@ }, { "cell_type": "code", - "execution_count": 34, - "metadata": { - "collapsed": false - }, + "execution_count": 31, + "metadata": {}, "outputs": [ { "data": { @@ -2445,7 +2418,7 @@ "[5]" ] }, - "execution_count": 34, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -2456,10 +2429,8 @@ }, { "cell_type": "code", - "execution_count": 35, - "metadata": { - "collapsed": false - }, + "execution_count": 32, + "metadata": {}, "outputs": [ { "data": { @@ -2467,7 +2438,7 @@ "[{'abbe', 'able', 'ably', 'ally', 'axle'}]" ] }, - "execution_count": 35, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -2478,10 +2449,67 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 76, "metadata": { - "collapsed": false + "scrolled": true }, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'demo', 'memo'},\n", + " {'thou', 'thru'},\n", + " {'crud', 'crux'},\n", + " {'bevy', 'levy'},\n", + " {'ogle', 'ogre'},\n", + " {'idol', 'idyl'},\n", + " {'also', 'alto', 'auto'},\n", + " {'used', 'user', 'uses'},\n", + " {'idle', 'idly', 'isle'},\n", + " {'eddy', 'edge', 'edgy'},\n", + " {'opal', 'oral', 'oval'},\n", + " {'icon', 'ikon', 'iron'},\n", + " {'afar', 'agar', 'ajar'},\n", + " {'each', 'etch', 'inch', 'itch'},\n", + " {'high', 'nigh', 'sigh', 'sign'},\n", + " {'abbe', 'able', 'ably', 'ally', 'axle'},\n", + " {'info', 'into', 'onto', 'undo', 'unto'},\n", + " {'ache', 'achy', 'acme', 'acne', 'acre', 'ashy'}]" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted((r for r in reachables if len(r) > 1 if len(r) < 10), key=len)" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'adze; agog; ague; ahoy; alga; ammo; amok; anal; ankh; apse; aqua; aura; avow; awol; bozo; ebbs; echo; ecru; emus; ends; envy; epee; epic; espy; euro; evil; exam; expo; guru; hymn; ibex; iffy; imam; iota; isms; judo; kiwi; liar; luau; lynx; mayo; meow; myna; nova; obey; oboe; odor; ohms; okra; oleo; once; onyx; orgy; ovum; rely; rhea; semi; sexy; stye; sync; taxi; tofu; tuft; tutu; twos; ugly; ulna; upon; urge; uric; urns; void; wiki; yeti; zebu'" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'; '.join(sorted(list(r)[0] for r in reachables if len(r) == 1))" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, "outputs": [ { "data": { @@ -2489,7 +2517,7 @@ "['buns', 'bunk', 'punk']" ] }, - "execution_count": 36, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -2500,7 +2528,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 34, "metadata": { "collapsed": true }, @@ -2515,7 +2543,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 35, "metadata": { "collapsed": true }, @@ -2538,7 +2566,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 36, "metadata": { "collapsed": true }, @@ -2549,35 +2577,33 @@ }, { "cell_type": "code", - "execution_count": 40, - "metadata": { - "collapsed": false - }, + "execution_count": 37, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['bops', 'bogs', 'begs', 'bees', 'byes', 'eyes', 'eyed']\n", - "['foal', 'foil', 'fail']\n", - "['bush', 'bash', 'base', 'bale', 'ball', 'boll']\n", - "['rift', 'lift', 'life', 'live', 'give', 'gave']\n", - "['club', 'clue', 'flue', 'flee', 'fled', 'pled', 'pied', 'lied', 'lien', 'mien']\n", - "['rung', 'dung', 'ding', 'dins', 'dies', 'lies', 'lien']\n", - "['baas', 'bags', 'bugs', 'bums', 'sums', 'sumo']\n", - "['fits', 'bits', 'bins', 'bind']\n", - "['lids', 'bids', 'bias', 'boas', 'boat', 'boot', 'soot', 'snot', 'snob']\n", - "['cake', 'came', 'cams', 'caws', 'cows', 'tows']\n", - "['tort', 'toot', 'trot', 'troy', 'tray', 'tram', 'cram']\n", - "['sews', 'pews', 'pees', 'peed', 'pied']\n", - "['lack', 'hack', 'hawk', 'haws', 'hows', 'tows']\n", - "['dots', 'dons', 'dens', 'dent', 'pent', 'pest', 'peso']\n", - "['ekes', 'eyes', 'byes', 'bees', 'beet', 'bent', 'lent', 'lept']\n", - "['ruin', 'rain', 'gain', 'grin', 'grid', 'arid', 'acid', 'aced', 'iced']\n", - "['sing', 'sins', 'bins', 'bias', 'bras', 'bray', 'tray', 'trap']\n", - "['lira', 'lire', 'wire', 'wise', 'wish']\n", - "['gash', 'cash', 'case', 'cape', 'rape']\n", - "['crop', 'coop', 'coot', 'loot', 'loft']\n" + "['army', 'arms', 'aims', 'aids', 'bids', 'bias', 'boas', 'boat', 'goat', 'gnat', 'gnaw']\n", + "['hoes', 'toes', 'toms', 'tams', 'tame']\n", + "['vane', 'vine', 'wine', 'wire', 'wiry', 'airy', 'awry', 'away']\n", + "['mate', 'late', 'lane', 'land', 'laid', 'lain']\n", + "['heal', 'head', 'bead', 'bend', 'bond', 'bone']\n", + "['dune', 'dine', 'dins', 'dies', 'died', 'tied']\n", + "['ions', 'dons', 'does', 'hoes', 'hoed', 'heed']\n", + "['puck', 'pick', 'pink', 'mink', 'mine']\n", + "['need', 'deed', 'died', 'dies', 'dims', 'dams', 'days', 'drys']\n", + "['pore', 'core', 'code', 'cods', 'cuds']\n", + "['mote', 'mite', 'mile', 'wile', 'wise']\n", + "['wait', 'wail', 'mail', 'mall', 'male']\n", + "['wail', 'bail', 'ball', 'boll', 'bolt', 'boot', 'boom', 'zoom']\n", + "['beat', 'beet', 'bees', 'bets', 'bats', 'cats']\n", + "['tore', 'tire', 'tile', 'vile', 'vise', 'visa']\n", + "['went', 'pent', 'pant']\n", + "['lick', 'sick', 'sics', 'sips', 'sops', 'oops']\n", + "['womb', 'tomb', 'toms', 'toes', 'does', 'dyes', 'ayes', 'apes', 'aped']\n", + "['cure', 'sure']\n", + "['cute', 'cuts', 'guts', 'guys', 'gays']\n" ] } ], @@ -2589,10 +2615,8 @@ }, { "cell_type": "code", - "execution_count": 41, - "metadata": { - "collapsed": false - }, + "execution_count": 38, + "metadata": {}, "outputs": [ { "data": { @@ -2600,7 +2624,7 @@ "['cops', 'coos', 'coon', 'coin', 'chin', 'thin', 'this', 'thus', 'thug']" ] }, - "execution_count": 41, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -2611,10 +2635,8 @@ }, { "cell_type": "code", - "execution_count": 42, - "metadata": { - "collapsed": false - }, + "execution_count": 39, + "metadata": {}, "outputs": [ { "data": { @@ -2622,7 +2644,7 @@ "[2204]" ] }, - "execution_count": 42, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -2633,10 +2655,8 @@ }, { "cell_type": "code", - "execution_count": 73, - "metadata": { - "collapsed": false - }, + "execution_count": 40, + "metadata": {}, "outputs": [ { "data": { @@ -2644,7 +2664,7 @@ "[2204]" ] }, - "execution_count": 73, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -2655,10 +2675,8 @@ }, { "cell_type": "code", - "execution_count": 43, - "metadata": { - "collapsed": false - }, + "execution_count": 41, + "metadata": {}, "outputs": [ { "data": { @@ -2666,7 +2684,7 @@ "['hate', 'have', 'hove', 'love']" ] }, - "execution_count": 43, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -2677,10 +2695,8 @@ }, { "cell_type": "code", - "execution_count": 44, - "metadata": { - "collapsed": false - }, + "execution_count": 42, + "metadata": {}, "outputs": [ { "data": { @@ -2688,7 +2704,7 @@ "['wars', 'ware', 'wave', 'wove', 'love']" ] }, - "execution_count": 44, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -2699,17 +2715,15 @@ }, { "cell_type": "code", - "execution_count": 45, - "metadata": { - "collapsed": false - }, + "execution_count": 43, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 0 ns, sys: 0 ns, total: 0 ns\n", - "Wall time: 850 µs\n" + "Wall time: 185 µs\n" ] }, { @@ -2718,7 +2732,7 @@ "5" ] }, - "execution_count": 45, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -2729,17 +2743,15 @@ }, { "cell_type": "code", - "execution_count": 46, - "metadata": { - "collapsed": false - }, + "execution_count": 44, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 0 ns, sys: 0 ns, total: 0 ns\n", - "Wall time: 353 µs\n" + "Wall time: 398 µs\n" ] }, { @@ -2748,7 +2760,7 @@ "5" ] }, - "execution_count": 46, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -2759,17 +2771,15 @@ }, { "cell_type": "code", - "execution_count": 47, - "metadata": { - "collapsed": false - }, + "execution_count": 45, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 76 ms, sys: 0 ns, total: 76 ms\n", - "Wall time: 75.1 ms\n" + "CPU times: user 32 ms, sys: 0 ns, total: 32 ms\n", + "Wall time: 32.3 ms\n" ] }, { @@ -2778,7 +2788,7 @@ "404" ] }, - "execution_count": 47, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -2789,9 +2799,9 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -2800,21 +2810,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CPU times: user 212 ms, sys: 0 ns, total: 212 ms\n", + "Wall time: 213 ms\n" + ] + }, + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%time len(bfs_search_closed('wars', 'love'))" ] }, { "cell_type": "code", - "execution_count": 50, - "metadata": { - "collapsed": false - }, + "execution_count": 48, + "metadata": {}, "outputs": [ { "data": { @@ -2822,7 +2847,7 @@ "['fear', 'feat', 'fest', 'lest', 'lost', 'lose', 'love']" ] }, - "execution_count": 50, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -2833,10 +2858,8 @@ }, { "cell_type": "code", - "execution_count": 51, - "metadata": { - "collapsed": false - }, + "execution_count": 49, + "metadata": {}, "outputs": [ { "data": { @@ -2844,7 +2867,7 @@ "['fail', 'fall', 'pall', 'pals', 'pass']" ] }, - "execution_count": 51, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -2855,10 +2878,8 @@ }, { "cell_type": "code", - "execution_count": 52, - "metadata": { - "collapsed": false - }, + "execution_count": 50, + "metadata": {}, "outputs": [ { "data": { @@ -2866,7 +2887,7 @@ "['star', 'soar', 'boar', 'boor', 'boon', 'born']" ] }, - "execution_count": 52, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -2877,10 +2898,8 @@ }, { "cell_type": "code", - "execution_count": 53, - "metadata": { - "collapsed": false - }, + "execution_count": 51, + "metadata": {}, "outputs": [ { "data": { @@ -2898,7 +2917,7 @@ " 'pass']" ] }, - "execution_count": 53, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -2909,10 +2928,8 @@ }, { "cell_type": "code", - "execution_count": 54, - "metadata": { - "collapsed": false - }, + "execution_count": 52, + "metadata": {}, "outputs": [ { "data": { @@ -2933,7 +2950,7 @@ " 'past']" ] }, - "execution_count": 54, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -2944,10 +2961,8 @@ }, { "cell_type": "code", - "execution_count": 55, - "metadata": { - "collapsed": false - }, + "execution_count": 53, + "metadata": {}, "outputs": [ { "data": { @@ -2955,7 +2970,7 @@ "[1]" ] }, - "execution_count": 55, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -2966,10 +2981,8 @@ }, { "cell_type": "code", - "execution_count": 56, - "metadata": { - "collapsed": false - }, + "execution_count": 54, + "metadata": {}, "outputs": [ { "data": { @@ -2977,7 +2990,7 @@ "[2204]" ] }, - "execution_count": 56, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -2988,16 +3001,14 @@ }, { "cell_type": "code", - "execution_count": 57, - "metadata": { - "collapsed": false - }, + "execution_count": 55, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 loop, best of 3: 12.3 s per loop\n" + "1 loop, best of 3: 8.21 s per loop\n" ] } ], @@ -3008,16 +3019,14 @@ }, { "cell_type": "code", - "execution_count": 58, - "metadata": { - "collapsed": false - }, + "execution_count": 56, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 loop, best of 3: 200 ms per loop\n" + "10 loops, best of 3: 145 ms per loop\n" ] } ], @@ -3028,10 +3037,8 @@ }, { "cell_type": "code", - "execution_count": 59, - "metadata": { - "collapsed": false - }, + "execution_count": 57, + "metadata": {}, "outputs": [ { "data": { @@ -3048,7 +3055,7 @@ " 'exit']" ] }, - "execution_count": 59, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -3059,55 +3066,31 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 58, "metadata": { - "collapsed": false + "collapsed": true }, - "outputs": [ - { - "data": { - "text/plain": [ - "{2: [['exes', 'exec'], ['rush', 'tush'], ['wile', 'wily'], ['shoo', 'shot']],\n", - " 3: [['bins', 'fink'], ['waft', 'wand'], ['heel', 'jell'], ['tent', 'west']],\n", - " 4: [['yore', 'polo'], ['hale', 'case'], ['horn', 'look'], ['tang', 'nuns']],\n", - " 5: [['crab', 'baas'], ['yens', 'dead'], ['work', 'paps'], ['tune', 'zaps']],\n", - " 6: [['mist', 'sold'], ['bats', 'sort'], ['leek', 'mads'], ['loop', 'dome']],\n", - " 7: [['rime', 'hoof'], ['grim', 'reed'], ['lies', 'eave'], ['ties', 'whiz']],\n", - " 8: [['drag', 'lied'], ['ages', 'yawl'], ['earl', 'deal'], ['gins', 'scab']],\n", - " 9: [['tyre', 'swum'], ['dike', 'flux'], ['hour', 'laze'], ['trek', 'bait']],\n", - " 10: [['ides', 'rasp'], ['egos', 'racy'], ['shim', 'ills'], ['bark', 'arty']],\n", - " 11: [['ergo', 'apex'], ['whey', 'owns'], ['anew', 'rapt'], ['thug', 'bate']],\n", - " 12: [['ream', 'imps'], ['meat', 'umps'], ['daze', 'knee'], ['clay', 'over']],\n", - " 13: [['oxen', 'blab'], ['blip', 'omen'], ['twig', 'ibis'], ['chew', 'umps']],\n", - " 14: [['amen', 'blip'], ['umps', 'futz'], ['amps', 'glib'], ['chum', 'whys']],\n", - " 15: [['thug', 'ibis']]}" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "solutions = {}\n", - "for _ in range(10000):\n", - " start, goal = random.sample(bigset, 2)\n", - " solution = astar_search_closed(start, goal)\n", - " sl = len(solution)\n", - " if sl not in solutions:\n", - " solutions[sl] = []\n", - " if len(solutions[sl]) < 4:\n", - " solutions[sl].append([start, goal])\n", + "# solutions = {}\n", + "# for _ in range(10000):\n", + "# start, goal = random.sample(bigset, 2)\n", + "# solution = astar_search_closed(start, goal)\n", + "# sl = len(solution)\n", + "# if sl not in solutions:\n", + "# solutions[sl] = []\n", + "# if len(solutions[sl]) < 4:\n", + "# solutions[sl].append([start, goal])\n", " \n", - "# if len(solution) >= 10:\n", - "# solutions += [solution]\n", + "# # if len(solution) >= 10:\n", + "# # solutions += [solution]\n", " \n", - "solutions" + "# solutions" ] }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 59, "metadata": { "collapsed": true }, @@ -3132,16 +3115,14 @@ }, { "cell_type": "code", - "execution_count": 66, - "metadata": { - "collapsed": false - }, + "execution_count": 60, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 loop, best of 3: 487 ms per loop\n" + "1 loop, best of 3: 334 ms per loop\n" ] } ], @@ -3152,17 +3133,15 @@ }, { "cell_type": "code", - "execution_count": 67, - "metadata": { - "collapsed": false - }, + "execution_count": 61, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 768 ms, sys: 0 ns, total: 768 ms\n", - "Wall time: 768 ms\n" + "CPU times: user 344 ms, sys: 0 ns, total: 344 ms\n", + "Wall time: 342 ms\n" ] }, { @@ -3171,7 +3150,7 @@ "14" ] }, - "execution_count": 67, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } @@ -3182,17 +3161,15 @@ }, { "cell_type": "code", - "execution_count": 68, - "metadata": { - "collapsed": false - }, + "execution_count": 62, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 176 ms, sys: 0 ns, total: 176 ms\n", - "Wall time: 176 ms\n" + "CPU times: user 92 ms, sys: 0 ns, total: 92 ms\n", + "Wall time: 93.7 ms\n" ] }, { @@ -3201,7 +3178,7 @@ "15" ] }, - "execution_count": 68, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -3212,17 +3189,15 @@ }, { "cell_type": "code", - "execution_count": 69, - "metadata": { - "collapsed": false - }, + "execution_count": 63, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 72 ms, sys: 0 ns, total: 72 ms\n", - "Wall time: 70.6 ms\n" + "CPU times: user 32 ms, sys: 0 ns, total: 32 ms\n", + "Wall time: 32.8 ms\n" ] }, { @@ -3231,7 +3206,7 @@ "14" ] }, - "execution_count": 69, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -3242,17 +3217,15 @@ }, { "cell_type": "code", - "execution_count": 70, - "metadata": { - "collapsed": false - }, + "execution_count": 64, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 32 ms, sys: 0 ns, total: 32 ms\n", - "Wall time: 35.7 ms\n" + "CPU times: user 16 ms, sys: 0 ns, total: 16 ms\n", + "Wall time: 16.4 ms\n" ] }, { @@ -3261,7 +3234,7 @@ "14" ] }, - "execution_count": 70, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } @@ -3272,17 +3245,15 @@ }, { "cell_type": "code", - "execution_count": 71, - "metadata": { - "collapsed": false - }, + "execution_count": 65, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 376 ms, sys: 4 ms, total: 380 ms\n", - "Wall time: 382 ms\n" + "CPU times: user 256 ms, sys: 0 ns, total: 256 ms\n", + "Wall time: 253 ms\n" ] }, { @@ -3291,7 +3262,7 @@ "14" ] }, - "execution_count": 71, + "execution_count": 65, "metadata": {}, "output_type": "execute_result" } @@ -3302,17 +3273,15 @@ }, { "cell_type": "code", - "execution_count": 72, - "metadata": { - "collapsed": false - }, + "execution_count": 66, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 72 ms, sys: 4 ms, total: 76 ms\n", - "Wall time: 76.9 ms\n" + "CPU times: user 36 ms, sys: 0 ns, total: 36 ms\n", + "Wall time: 34.2 ms\n" ] }, { @@ -3321,7 +3290,7 @@ "14" ] }, - "execution_count": 72, + "execution_count": 66, "metadata": {}, "output_type": "execute_result" } @@ -3330,6 +3299,133 @@ "%time len(astar_search_closed('imps', 'pros'))" ] }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "bash bush True\n", + "rush bush True\n" + ] + }, + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nb_count = collections.Counter()\n", + "for w in neighbours['rash']:\n", + " for w2 in neighbours[w]:\n", + " if w2 == 'bush': print(w, w2, w2 not in neighbours['rash'])\n", + " if w2 != 'rash' and w2 not in neighbours['rash']:\n", + " nb_count.update([w2])\n", + "nb_count.most_common(1)[0][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['gush', 'hush', 'lush', 'mush', 'push', 'tush', 'bosh']" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[w for w in neighbours['bush'] if w in nb_count]" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('nose', 2)" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "best_start = ''\n", + "best_overlap_count = 0\n", + "for w0 in neighbours: \n", + " nb_count = collections.Counter()\n", + " for w in neighbours[w0]:\n", + " for w2 in neighbours[w]:\n", + " if w2 != w0 and w2 not in neighbours[w0]:\n", + " nb_count.update([w2])\n", + " if len(nb_count) > 0:\n", + " if nb_count.most_common(1)[0][1] > best_overlap_count:\n", + " best_start = w0\n", + " best_overlap_count = nb_count.most_common(1)[0][1]\n", + " \n", + "best_start, best_overlap_count" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'grew'" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "w0" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'bash', 'rush'}" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set(neighbours['rash']) & set(neighbours['bush'])" + ] + }, { "cell_type": "code", "execution_count": null, @@ -3356,7 +3452,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.5.2+" } }, "nbformat": 4,