"cells": [
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 1,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 3,
"metadata": {},
"outputs": [
{
"2336"
]
},
- "execution_count": 5,
+ "execution_count": 3,
"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,
+ "execution_count": 4,
"metadata": {},
"outputs": [
{
" 'achy']"
]
},
- "execution_count": 6,
+ "execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 5,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 6,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 7,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 8,
"metadata": {},
"outputs": [
{
"['able']"
]
},
- "execution_count": 10,
+ "execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 9,
"metadata": {},
"outputs": [
{
"['axle', 'abbe', 'ably']"
]
},
- "execution_count": 11,
+ "execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 10,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 11,
"metadata": {},
"outputs": [
{
"0"
]
},
- "execution_count": 13,
+ "execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 12,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": 13,
"metadata": {},
"outputs": [
{
"[['abbe', 'able']]"
]
},
- "execution_count": 15,
+ "execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 16,
+ "execution_count": 14,
"metadata": {},
"outputs": [
{
"[['abbe', 'able', 'axle'], ['abbe', 'able', 'ably']]"
]
},
- "execution_count": 16,
+ "execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 17,
+ "execution_count": 15,
"metadata": {},
"outputs": [
{
"[['abbe', 'able', 'ably', 'ally']]"
]
},
- "execution_count": 17,
+ "execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 18,
+ "execution_count": 16,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 19,
+ "execution_count": 17,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 18,
"metadata": {},
"outputs": [
{
"['abbe', 'able', 'ably', 'ally']"
]
},
- "execution_count": 20,
+ "execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": 19,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": 20,
"metadata": {},
"outputs": [
{
"['abbe', 'able', 'ably', 'ally']"
]
},
- "execution_count": 22,
+ "execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 23,
+ "execution_count": 21,
"metadata": {},
"outputs": [
{
"['cart', 'part', 'park', 'pars']\n",
"['cart', 'part', 'pars', 'bars']\n",
"['cart', 'part', 'pars', 'cars']\n",
- "['cart', 'part', 'pars', 'ears']\n",
+ "['cart', 'part', 'pars', 'ears']\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
"['cart', 'part', 'pars', 'jars']\n",
"['cart', 'part', 'pars', 'mars']\n",
"['cart', 'part', 'pars', 'oars']\n",
"['cart', 'cant', 'cans', 'vans']"
]
},
- "execution_count": 23,
+ "execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 24,
+ "execution_count": 22,
"metadata": {},
"outputs": [
{
"['cart', 'cant', 'cane', 'vane']"
]
},
- "execution_count": 24,
+ "execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 25,
+ "execution_count": 23,
"metadata": {},
"outputs": [
{
" 'vane']"
]
},
- "execution_count": 25,
+ "execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 26,
+ "execution_count": 24,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 27,
+ "execution_count": 25,
"metadata": {},
"outputs": [
{
"['cart', 'cant', 'cane', 'vane']"
]
},
- "execution_count": 27,
+ "execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 28,
+ "execution_count": 26,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 29,
+ "execution_count": 27,
"metadata": {},
"outputs": [
{
"['cart', 'cant', 'cane', 'vane']"
]
},
- "execution_count": 29,
+ "execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 30,
+ "execution_count": 28,
"metadata": {},
"outputs": [
{
"94"
]
},
- "execution_count": 30,
+ "execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 31,
+ "execution_count": 29,
"metadata": {},
"outputs": [
{
"2204"
]
},
- "execution_count": 31,
+ "execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 32,
+ "execution_count": 30,
"metadata": {},
"outputs": [
{
"1"
]
},
- "execution_count": 32,
+ "execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": 31,
"metadata": {
"scrolled": true
},
"Counter({1: 75, 2: 6, 3: 7, 4: 2, 5: 2, 6: 1, 2204: 1})"
]
},
- "execution_count": 33,
+ "execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 34,
+ "execution_count": 32,
"metadata": {},
"outputs": [
{
"[5]"
]
},
- "execution_count": 34,
+ "execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 35,
+ "execution_count": 33,
"metadata": {},
"outputs": [
{
"[{'abbe', 'able', 'ably', 'ally', 'axle'}]"
]
},
- "execution_count": 35,
+ "execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 36,
+ "execution_count": 34,
"metadata": {},
"outputs": [
{
"['buns', 'bunk', 'punk']"
]
},
- "execution_count": 36,
+ "execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 37,
+ "execution_count": 35,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 38,
+ "execution_count": 36,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 39,
+ "execution_count": 37,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 40,
+ "execution_count": 38,
"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"
+ "['drip', 'grip', 'grit', 'gait', 'bait', 'bast', 'base', 'babe']\n",
+ "['cape', 'cope', 'dope', 'dole', 'dolt']\n",
+ "['laze', 'late', 'lats', 'pats']\n",
+ "['zest', 'best', 'bust', 'buss', 'buds', 'suds']\n",
+ "['gape', 'gaps', 'paps', 'peps', 'pees', 'peel']\n",
+ "['yogi', 'yoga', 'toga', 'togs', 'tors', 'tore']\n",
+ "['flux', 'flex', 'fled', 'feed', 'fees', 'foes', 'toes', 'toys']\n",
+ "['bike', 'bake', 'base', 'bast', 'best', 'beet', 'feet']\n",
+ "['tows', 'lows', 'laws', 'lams', 'lame']\n",
+ "['jock', 'pock', 'pork', 'pore', 'pure']\n",
+ "['tabu', 'tabs', 'cabs', 'caws', 'cows', 'cowl', 'coil', 'coif']\n",
+ "['reek', 'week', 'wees', 'weds', 'wads', 'wadi']\n",
+ "['gene', 'gone', 'gong', 'song']\n",
+ "['mete', 'mate', 'bate', 'bats', 'baas', 'bras', 'brag', 'crag', 'cram']\n",
+ "['gnus', 'anus', 'ants', 'acts', 'aces', 'ayes', 'byes', 'bees', 'been', 'teen']\n",
+ "['comb', 'come', 'core', 'corn', 'torn', 'tern']\n",
+ "['ouch', 'much', 'muck', 'buck', 'beck', 'beak', 'beat', 'teat', 'that', 'than', 'khan']\n",
+ "['rids', 'reds', 'reps', 'peps', 'peas', 'peal', 'deal']\n",
+ "['calm', 'balm', 'bald', 'bold', 'bolt', 'bout', 'tout']\n",
+ "['toed', 'toad', 'goad', 'grad', 'gray', 'grey', 'grew']\n"
]
}
],
},
{
"cell_type": "code",
- "execution_count": 41,
+ "execution_count": 39,
"metadata": {},
"outputs": [
{
"['cops', 'coos', 'coon', 'coin', 'chin', 'thin', 'this', 'thus', 'thug']"
]
},
- "execution_count": 41,
+ "execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 42,
+ "execution_count": 40,
"metadata": {},
"outputs": [
{
"[2204]"
]
},
- "execution_count": 42,
+ "execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 73,
+ "execution_count": 41,
"metadata": {},
"outputs": [
{
"[2204]"
]
},
- "execution_count": 73,
+ "execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 43,
+ "execution_count": 42,
"metadata": {},
"outputs": [
{
"['hate', 'have', 'hove', 'love']"
]
},
- "execution_count": 43,
+ "execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 44,
+ "execution_count": 43,
"metadata": {},
"outputs": [
{
"['wars', 'ware', 'wave', 'wove', 'love']"
]
},
- "execution_count": 44,
+ "execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 45,
+ "execution_count": 44,
"metadata": {},
"outputs": [
{
"output_type": "stream",
"text": [
"CPU times: user 0 ns, sys: 0 ns, total: 0 ns\n",
- "Wall time: 850 µs\n"
+ "Wall time: 212 µs\n"
]
},
{
"5"
]
},
- "execution_count": 45,
+ "execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 46,
+ "execution_count": 45,
"metadata": {},
"outputs": [
{
"output_type": "stream",
"text": [
"CPU times: user 0 ns, sys: 0 ns, total: 0 ns\n",
- "Wall time: 353 µs\n"
+ "Wall time: 203 µs\n"
]
},
{
"5"
]
},
- "execution_count": 46,
+ "execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 47,
+ "execution_count": 46,
"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 24 ms, sys: 0 ns, total: 24 ms\n",
+ "Wall time: 23.2 ms\n"
]
},
{
"404"
]
},
- "execution_count": 47,
+ "execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
+ "execution_count": 47,
+ "metadata": {
+ "collapsed": true
+ },
"outputs": [],
"source": [
"# %time len(bfs_search('wars', 'love'))"
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 48,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "CPU times: user 332 ms, sys: 0 ns, total: 332 ms\n",
+ "Wall time: 331 ms\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "5"
+ ]
+ },
+ "execution_count": 48,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"%time len(bfs_search_closed('wars', 'love'))"
]
},
{
"cell_type": "code",
- "execution_count": 50,
+ "execution_count": 49,
"metadata": {},
"outputs": [
{
"['fear', 'feat', 'fest', 'lest', 'lost', 'lose', 'love']"
]
},
- "execution_count": 50,
+ "execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 51,
+ "execution_count": 50,
"metadata": {},
"outputs": [
{
"['fail', 'fall', 'pall', 'pals', 'pass']"
]
},
- "execution_count": 51,
+ "execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 52,
+ "execution_count": 51,
"metadata": {},
"outputs": [
{
"['star', 'soar', 'boar', 'boor', 'boon', 'born']"
]
},
- "execution_count": 52,
+ "execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 53,
+ "execution_count": 52,
"metadata": {},
"outputs": [
{
" 'pass']"
]
},
- "execution_count": 53,
+ "execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 54,
+ "execution_count": 53,
"metadata": {},
"outputs": [
{
" 'past']"
]
},
- "execution_count": 54,
+ "execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 55,
+ "execution_count": 54,
"metadata": {},
"outputs": [
{
"[1]"
]
},
- "execution_count": 55,
+ "execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 56,
+ "execution_count": 55,
"metadata": {},
"outputs": [
{
"[2204]"
]
},
- "execution_count": 56,
+ "execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 57,
+ "execution_count": 56,
"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.08 s per loop\n"
]
}
],
},
{
"cell_type": "code",
- "execution_count": 58,
+ "execution_count": 57,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
- "1 loop, best of 3: 200 ms per loop\n"
+ "10 loops, best of 3: 131 ms per loop\n"
]
}
],
},
{
"cell_type": "code",
- "execution_count": 59,
+ "execution_count": 58,
"metadata": {},
"outputs": [
{
" 'exit']"
]
},
- "execution_count": 59,
+ "execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 60,
+ "execution_count": 68,
"metadata": {},
- "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": 60,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 66,
+ "execution_count": 61,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
- "1 loop, best of 3: 487 ms per loop\n"
+ "1 loop, best of 3: 352 ms per loop\n"
]
}
],
},
{
"cell_type": "code",
- "execution_count": 67,
+ "execution_count": 62,
"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 452 ms, sys: 0 ns, total: 452 ms\n",
+ "Wall time: 449 ms\n"
]
},
{
"14"
]
},
- "execution_count": 67,
+ "execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 68,
+ "execution_count": 63,
"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: 91.5 ms\n"
]
},
{
"15"
]
},
- "execution_count": 68,
+ "execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 69,
+ "execution_count": 64,
"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: 31.4 ms\n"
]
},
{
"14"
]
},
- "execution_count": 69,
+ "execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 70,
+ "execution_count": 65,
"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: 17.2 ms\n"
]
},
{
"14"
]
},
- "execution_count": 70,
+ "execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 71,
+ "execution_count": 66,
"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 296 ms, sys: 4 ms, total: 300 ms\n",
+ "Wall time: 299 ms\n"
]
},
{
"14"
]
},
- "execution_count": 71,
+ "execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 72,
+ "execution_count": 67,
"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.5 ms\n"
]
},
{
"14"
]
},
- "execution_count": 72,
+ "execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
"%time len(astar_search_closed('imps', 'pros'))"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 90,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "bash bush True\n",
+ "rush bush True\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "2"
+ ]
+ },
+ "execution_count": 90,
+ "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": 91,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['gush', 'hush', 'lush', 'mush', 'push', 'tush', 'bosh']"
+ ]
+ },
+ "execution_count": 91,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "[w for w in neighbours['bush'] if w in nb_count]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 89,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "('gibe', 2)"
+ ]
+ },
+ "execution_count": 89,
+ "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": 88,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'memo'"
+ ]
+ },
+ "execution_count": 88,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "w0"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 76,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'bash', 'rush'}"
+ ]
+ },
+ "execution_count": 76,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "set(neighbours['rash']) & set(neighbours['bush'])"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,