From: Neil Smith Date: Mon, 26 Jun 2017 19:30:13 +0000 (+0100) Subject: Finished amijakuji part 1, added pictures X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=84f849f83970f3a6295d09da5c1bef1fe9cec4cb;p=ou-summer-of-code-2017.git Finished amijakuji part 1, added pictures --- diff --git a/04-08-amidakuji/04-small.txt b/04-08-amidakuji/04-small.txt index 5258d03..75e0d3d 100644 --- a/04-08-amidakuji/04-small.txt +++ b/04-08-amidakuji/04-small.txt @@ -1,20 +1,15 @@ -(2, 3) -(2, 6) -(3, 7) -(5, 6) -(0, 1) -(0, 1) -(6, 7) (2, 5) -(6, 9) -(4, 8) +(1, 4) +(0, 3) +(0, 3) +(0, 5) +(3, 5) (0, 2) -(5, 7) -(4, 8) -(1, 5) -(6, 8) -(6, 9) -(2, 5) -(1, 8) -(5, 7) -(2, 9) \ No newline at end of file +(3, 4) +(2, 4) +(1, 2) +(0, 4) +(1, 2) +(2, 4) +(0, 4) +(1, 4) \ No newline at end of file diff --git a/04-08-amidakuji/amidakuji-creation.ipynb b/04-08-amidakuji/amidakuji-creation.ipynb index c08756e..65d9751 100644 --- a/04-08-amidakuji/amidakuji-creation.ipynb +++ b/04-08-amidakuji/amidakuji-creation.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 36, "metadata": { "collapsed": true }, @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 37, "metadata": { "collapsed": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 38, "metadata": { "collapsed": true }, @@ -39,7 +39,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 39, "metadata": { "collapsed": true }, @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 40, "metadata": { "collapsed": true }, @@ -76,47 +76,42 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{Link(height=2, left=0, right=3),\n", - " Link(height=2, left=1, right=7),\n", - " Link(height=3, left=1, right=8),\n", - " Link(height=9, left=6, right=9),\n", - " Link(height=15, left=0, right=4),\n", - " Link(height=20, left=0, right=8),\n", - " Link(height=23, left=3, right=4),\n", - " Link(height=24, left=3, right=6),\n", - " Link(height=28, left=1, right=8),\n", - " Link(height=28, left=5, right=6),\n", - " Link(height=32, left=1, right=7),\n", - " Link(height=34, left=1, right=9),\n", - " Link(height=36, left=0, right=4),\n", - " Link(height=38, left=5, right=6),\n", - " Link(height=40, left=0, right=2),\n", - " Link(height=41, left=3, right=7),\n", - " Link(height=43, left=2, right=4),\n", - " Link(height=43, left=6, right=8),\n", - " Link(height=44, left=0, right=6),\n", - " Link(height=46, left=7, right=8)}" + "{Link(height=4, left=0, right=3),\n", + " Link(height=8, left=1, right=5),\n", + " Link(height=16, left=0, right=4),\n", + " Link(height=17, left=1, right=5),\n", + " Link(height=18, left=3, right=5),\n", + " Link(height=20, left=0, right=1),\n", + " Link(height=25, left=0, right=3),\n", + " Link(height=30, left=1, right=4),\n", + " Link(height=33, left=0, right=4),\n", + " Link(height=34, left=4, right=5),\n", + " Link(height=35, left=0, right=3),\n", + " Link(height=36, left=1, right=4),\n", + " Link(height=37, left=2, right=5),\n", + " Link(height=45, left=4, right=5),\n", + " Link(height=46, left=2, right=5)}" ] }, - "execution_count": 6, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "net = make_net(20)\n", + "net = make_net(15, lines=6)\n", "net" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 42, "metadata": { "collapsed": true }, @@ -135,7 +130,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -144,7 +139,7 @@ "3" ] }, - "execution_count": 8, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -155,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 44, "metadata": { "collapsed": true }, @@ -174,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 45, "metadata": { "collapsed": true }, @@ -188,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 46, "metadata": { "collapsed": true }, @@ -209,25 +204,25 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 47, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10000 loops, best of 3: 45.7 µs per loop\n" + "10000 loops, best of 3: 39.2 µs per loop\n" ] } ], "source": [ "%%timeit\n", - "follow_many('abcdefghij', net)" + "follow_many('abcdef', net)" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 48, "metadata": { "collapsed": true }, @@ -239,7 +234,7 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": 49, "metadata": { "collapsed": true }, @@ -259,16 +254,16 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'(0, 3), (1, 7), (1, 8), (6, 9), (0, 4), (0, 8), (3, 4), (3, 6), (1, 8), (5, 6), (1, 7), (1, 9), (0, 4), (5, 6), (0, 2), (3, 7), (2, 4), (6, 8), (0, 6), (7, 8)'" + "'(0, 3), (1, 5), (0, 4), (1, 5), (3, 5), (0, 1), (0, 3), (1, 4), (0, 4), (4, 5), (0, 3), (1, 4), (2, 5), (4, 5), (2, 5)'" ] }, - "execution_count": 105, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -279,16 +274,16 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'(1, 7), (0, 3), (1, 8), (6, 9), (0, 4), (0, 8), (3, 4), (3, 6), (5, 6), (1, 8), (1, 7), (1, 9), (0, 4), (5, 6), (0, 2), (3, 7), (6, 8), (2, 4), (0, 6), (7, 8)'" + "'(0, 3), (1, 5), (0, 4), (1, 5), (3, 5), (0, 1), (0, 3), (1, 4), (0, 4), (4, 5), (0, 3), (1, 4), (2, 5), (4, 5), (2, 5)'" ] }, - "execution_count": 106, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -299,16 +294,16 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'(0, 3) : (1, 7) : (1, 8) : (6, 9) : (0, 4) : (0, 8) : (3, 4) : (3, 6) : (1, 8) : (5, 6) : (1, 7) : (1, 9) : (0, 4) : (5, 6) : (0, 2) : (3, 7) : (2, 4) : (6, 8) : (0, 6) : (7, 8)'" + "'(0, 3) : (1, 5) : (0, 4) : (1, 5) : (3, 5) : (0, 1) : (0, 3) : (1, 4) : (0, 4) : (4, 5) : (0, 3) : (1, 4) : (2, 5) : (4, 5) : (2, 5)'" ] }, - "execution_count": 110, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -319,16 +314,16 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'(0, 3)\\n(1, 7)\\n(1, 8)\\n(6, 9)\\n(0, 4)\\n(0, 8)\\n(3, 4)\\n(3, 6)\\n(1, 8)\\n(5, 6)\\n(1, 7)\\n(1, 9)\\n(0, 4)\\n(5, 6)\\n(0, 2)\\n(3, 7)\\n(2, 4)\\n(6, 8)\\n(0, 6)\\n(7, 8)'" + "'(0, 3)\\n(1, 5)\\n(0, 4)\\n(1, 5)\\n(3, 5)\\n(0, 1)\\n(0, 3)\\n(1, 4)\\n(0, 4)\\n(4, 5)\\n(0, 3)\\n(1, 4)\\n(2, 5)\\n(4, 5)\\n(2, 5)'" ] }, - "execution_count": 111, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -339,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": 54, "metadata": { "scrolled": true }, @@ -349,25 +344,20 @@ "output_type": "stream", "text": [ "(0, 3)\n", - "(1, 7)\n", - "(1, 8)\n", - "(6, 9)\n", + "(1, 5)\n", "(0, 4)\n", - "(0, 8)\n", - "(3, 4)\n", - "(3, 6)\n", - "(1, 8)\n", - "(5, 6)\n", - "(1, 7)\n", - "(1, 9)\n", + "(1, 5)\n", + "(3, 5)\n", + "(0, 1)\n", + "(0, 3)\n", + "(1, 4)\n", "(0, 4)\n", - "(5, 6)\n", - "(0, 2)\n", - "(3, 7)\n", - "(2, 4)\n", - "(6, 8)\n", - "(0, 6)\n", - "(7, 8)\n" + "(4, 5)\n", + "(0, 3)\n", + "(1, 4)\n", + "(2, 5)\n", + "(4, 5)\n", + "(2, 5)\n" ] } ], @@ -377,16 +367,25 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "# open('04-small.txt', 'w').write(show_net(net))" + ] + }, + { + "cell_type": "code", + "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'(0, 3), (1, 7), (1, 8), (6, 9), (0, 4), (0, 8), (3, 4), (3, 6), (1, 8), (5, 6), (1, 7), (1, 9), (0, 4), (5, 6), (0, 2), (3, 7), (2, 4), (6, 8), (0, 6), (7, 8)'" + "'(0, 3), (1, 5), (0, 4), (1, 5), (3, 5), (0, 1), (0, 3), (1, 4), (0, 4), (4, 5), (0, 3), (1, 4), (2, 5), (4, 5), (2, 5)'" ] }, - "execution_count": 108, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } @@ -397,7 +396,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 57, "metadata": {}, "outputs": [ { @@ -406,7 +405,7 @@ "[]" ] }, - "execution_count": 17, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -418,7 +417,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 58, "metadata": { "collapsed": true }, @@ -429,7 +428,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 59, "metadata": { "collapsed": true }, @@ -441,7 +440,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 60, "metadata": { "collapsed": true }, @@ -453,35 +452,41 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 61, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "net = read_net('(1, 5), (2, 4), (0, 2), (0, 4), (0, 1), (0, 2), (1, 5), (0, 3), (1, 2), (4, 5), (0, 5), (3, 5), (1, 4), (0, 1), (2, 3)')" + ] + }, + { + "cell_type": "code", + "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[Link(height=0, left=0, right=3),\n", - " Link(height=1, left=1, right=7),\n", - " Link(height=2, left=1, right=8),\n", - " Link(height=3, left=6, right=9),\n", - " Link(height=4, left=0, right=4),\n", - " Link(height=5, left=0, right=8),\n", - " Link(height=6, left=3, right=4),\n", - " Link(height=7, left=3, right=6),\n", - " Link(height=8, left=1, right=8),\n", - " Link(height=9, left=5, right=6),\n", - " Link(height=10, left=1, right=7),\n", - " Link(height=11, left=1, right=9),\n", - " Link(height=12, left=0, right=4),\n", - " Link(height=13, left=5, right=6),\n", - " Link(height=14, left=0, right=2),\n", - " Link(height=15, left=3, right=7),\n", - " Link(height=16, left=2, right=4),\n", - " Link(height=17, left=6, right=8),\n", - " Link(height=18, left=0, right=6),\n", - " Link(height=19, left=7, right=8)]" + "[Link(height=0, left=1, right=5),\n", + " Link(height=1, left=2, right=4),\n", + " Link(height=2, left=0, right=2),\n", + " Link(height=3, left=0, right=4),\n", + " Link(height=4, left=0, right=1),\n", + " Link(height=5, left=0, right=2),\n", + " Link(height=6, left=1, right=5),\n", + " Link(height=7, left=0, right=3),\n", + " Link(height=8, left=1, right=2),\n", + " Link(height=9, left=4, right=5),\n", + " Link(height=10, left=0, right=5),\n", + " Link(height=11, left=3, right=5),\n", + " Link(height=12, left=1, right=4),\n", + " Link(height=13, left=0, right=1),\n", + " Link(height=14, left=2, right=3)]" ] }, - "execution_count": 21, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -492,35 +497,30 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[Link(height=0, left=0, right=3),\n", - " Link(height=0, left=1, right=7),\n", - " Link(height=0, left=6, right=9),\n", - " Link(height=1, left=0, right=4),\n", - " Link(height=1, left=1, right=8),\n", - " Link(height=2, left=0, right=8),\n", - " Link(height=2, left=3, right=4),\n", - " Link(height=3, left=0, right=4),\n", - " Link(height=3, left=1, right=8),\n", - " Link(height=3, left=3, right=6),\n", + "[Link(height=0, left=1, right=5),\n", + " Link(height=0, left=2, right=4),\n", + " Link(height=1, left=0, right=2),\n", + " Link(height=2, left=0, right=4),\n", + " Link(height=3, left=0, right=1),\n", " Link(height=4, left=0, right=2),\n", - " Link(height=4, left=1, right=7),\n", - " Link(height=4, left=5, right=6),\n", - " Link(height=5, left=1, right=9),\n", - " Link(height=5, left=2, right=4),\n", - " Link(height=5, left=3, right=7),\n", - " Link(height=5, left=5, right=6),\n", - " Link(height=6, left=6, right=8),\n", - " Link(height=7, left=0, right=6),\n", - " Link(height=7, left=7, right=8)]" + " Link(height=4, left=1, right=5),\n", + " Link(height=5, left=0, right=3),\n", + " Link(height=5, left=1, right=2),\n", + " Link(height=5, left=4, right=5),\n", + " Link(height=6, left=0, right=5),\n", + " Link(height=6, left=1, right=4),\n", + " Link(height=7, left=0, right=1),\n", + " Link(height=7, left=3, right=5),\n", + " Link(height=8, left=2, right=3)]" ] }, - "execution_count": 22, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -531,35 +531,30 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[Link(height=0, left=0, right=3),\n", - " Link(height=0, left=1, right=7),\n", - " Link(height=0, left=6, right=9),\n", - " Link(height=1, left=0, right=4),\n", - " Link(height=1, left=1, right=8),\n", - " Link(height=2, left=0, right=8),\n", - " Link(height=2, left=3, right=4),\n", - " Link(height=3, left=0, right=4),\n", - " Link(height=3, left=1, right=8),\n", - " Link(height=3, left=3, right=6),\n", + "[Link(height=0, left=1, right=5),\n", + " Link(height=0, left=2, right=4),\n", + " Link(height=1, left=0, right=2),\n", + " Link(height=2, left=0, right=4),\n", + " Link(height=3, left=0, right=1),\n", " Link(height=4, left=0, right=2),\n", - " Link(height=4, left=1, right=7),\n", - " Link(height=4, left=5, right=6),\n", - " Link(height=5, left=1, right=9),\n", - " Link(height=5, left=2, right=4),\n", - " Link(height=5, left=3, right=7),\n", - " Link(height=5, left=5, right=6),\n", - " Link(height=6, left=6, right=8),\n", - " Link(height=7, left=0, right=6),\n", - " Link(height=7, left=7, right=8)]" + " Link(height=4, left=1, right=5),\n", + " Link(height=5, left=0, right=3),\n", + " Link(height=5, left=1, right=2),\n", + " Link(height=5, left=4, right=5),\n", + " Link(height=6, left=0, right=5),\n", + " Link(height=6, left=1, right=4),\n", + " Link(height=7, left=0, right=1),\n", + " Link(height=7, left=3, right=5),\n", + " Link(height=8, left=2, right=3)]" ] }, - "execution_count": 23, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } @@ -570,16 +565,16 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(False, True)" + "(True, True)" ] }, - "execution_count": 24, + "execution_count": 65, "metadata": {}, "output_type": "execute_result" } @@ -593,7 +588,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 66, "metadata": { "collapsed": true }, @@ -608,7 +603,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 67, "metadata": { "collapsed": true }, @@ -620,16 +615,16 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2224" + "2239" ] }, - "execution_count": 27, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -640,16 +635,16 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "99998" + "99989" ] }, - "execution_count": 28, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -660,7 +655,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 70, "metadata": {}, "outputs": [ { @@ -669,7 +664,7 @@ "10206" ] }, - "execution_count": 29, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } @@ -680,16 +675,16 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2224" + "2239" ] }, - "execution_count": 30, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -700,7 +695,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 72, "metadata": { "collapsed": true }, @@ -711,14 +706,14 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 73, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10 loops, best of 3: 23.4 ms per loop\n" + "10 loops, best of 3: 25.9 ms per loop\n" ] } ], @@ -729,7 +724,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 74, "metadata": { "collapsed": true }, @@ -741,7 +736,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 75, "metadata": { "collapsed": true }, @@ -758,7 +753,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 76, "metadata": { "collapsed": true }, @@ -777,14 +772,14 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 77, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10 loops, best of 3: 23.5 ms per loop\n" + "10 loops, best of 3: 24.1 ms per loop\n" ] } ], @@ -795,7 +790,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 78, "metadata": { "collapsed": true }, @@ -811,7 +806,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 79, "metadata": { "collapsed": true }, @@ -828,7 +823,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 80, "metadata": { "collapsed": true }, @@ -844,7 +839,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 81, "metadata": { "collapsed": true }, @@ -862,7 +857,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 82, "metadata": {}, "outputs": [ { @@ -875,10 +870,10 @@ { "data": { "text/plain": [ - "(10207, 9839)" + "(10207, 9813)" ] }, - "execution_count": 41, + "execution_count": 82, "metadata": {}, "output_type": "execute_result" } @@ -891,7 +886,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 83, "metadata": {}, "outputs": [ { @@ -900,7 +895,7 @@ "[]" ] }, - "execution_count": 42, + "execution_count": 83, "metadata": {}, "output_type": "execute_result" } @@ -911,7 +906,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 84, "metadata": { "collapsed": true }, @@ -923,14 +918,14 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 85, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 loop, best of 3: 5.77 s per loop\n" + "1 loop, best of 3: 6.08 s per loop\n" ] } ], @@ -941,7 +936,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 86, "metadata": { "collapsed": true }, @@ -954,7 +949,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 87, "metadata": { "collapsed": true }, @@ -965,7 +960,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 88, "metadata": { "collapsed": true }, @@ -987,7 +982,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 89, "metadata": { "collapsed": true }, @@ -1019,7 +1014,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 90, "metadata": { "collapsed": true }, @@ -1031,8 +1026,10 @@ }, { "cell_type": "code", - "execution_count": 50, - "metadata": {}, + "execution_count": 91, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "def triple_pair_hg(height_groups, debug=False):\n", @@ -1072,7 +1069,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 92, "metadata": { "collapsed": true }, @@ -1095,7 +1092,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 93, "metadata": { "collapsed": true }, @@ -1117,23 +1114,23 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 94, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[(Link(height=831, left=8, right=16),\n", - " Link(height=832, left=8, right=25),\n", - " Link(height=833, left=8, right=16),\n", - " Link(height=834, left=8, right=25)),\n", - " (Link(height=1657, left=1, right=13),\n", - " Link(height=1658, left=1, right=12),\n", - " Link(height=1659, left=1, right=13),\n", - " Link(height=1660, left=1, right=12))]" + "[(Link(height=1126, left=8, right=17),\n", + " Link(height=1127, left=1, right=8),\n", + " Link(height=1128, left=8, right=17),\n", + " Link(height=1129, left=1, right=8)),\n", + " (Link(height=1952, left=12, right=25),\n", + " Link(height=1953, left=10, right=12),\n", + " Link(height=1954, left=12, right=25),\n", + " Link(height=1955, left=10, right=12))]" ] }, - "execution_count": 53, + "execution_count": 94, "metadata": {}, "output_type": "execute_result" } @@ -1145,14 +1142,14 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 95, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10 loops, best of 3: 99.4 ms per loop\n" + "10 loops, best of 3: 98.7 ms per loop\n" ] } ], @@ -1164,7 +1161,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 96, "metadata": { "collapsed": true }, @@ -1182,7 +1179,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 97, "metadata": { "collapsed": true }, @@ -1200,8 +1197,10 @@ }, { "cell_type": "code", - "execution_count": 57, - "metadata": {}, + "execution_count": 98, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "etlnet = eliminate_a_triple_pair(elnet)" @@ -1209,8 +1208,10 @@ }, { "cell_type": "code", - "execution_count": 58, - "metadata": {}, + "execution_count": 99, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "assert follow_many(string.ascii_lowercase, etlnet) == follow_many(string.ascii_lowercase, elnet)" @@ -1218,16 +1219,16 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 100, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "9839\n", - "9839\n", - "9837\n" + "9813\n", + "9813\n", + "9811\n" ] } ], @@ -1237,16 +1238,16 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 101, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "9835" + "9809" ] }, - "execution_count": 60, + "execution_count": 101, "metadata": {}, "output_type": "execute_result" } @@ -1257,8 +1258,10 @@ }, { "cell_type": "code", - "execution_count": 61, - "metadata": {}, + "execution_count": 102, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "assert follow_many(string.ascii_lowercase, etlnet) == follow_many(string.ascii_lowercase, elnet)" @@ -1266,16 +1269,16 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'buxphgtzqykfawvomcjresnldi'" + "'ypetfugkzdsacbvwjohqlnirmx'" ] }, - "execution_count": 62, + "execution_count": 103, "metadata": {}, "output_type": "execute_result" } @@ -1286,16 +1289,16 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 104, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'buxphgtzqykfawvomcjresnldi'" + "'ypetfugkzdsacbvwjohqlnirmx'" ] }, - "execution_count": 63, + "execution_count": 104, "metadata": {}, "output_type": "execute_result" } @@ -1306,16 +1309,16 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 105, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'buxphgtzqykfawvomcjresnldi'" + "'ypetfugkzdsacbvwjohqlnirmx'" ] }, - "execution_count": 64, + "execution_count": 105, "metadata": {}, "output_type": "execute_result" } @@ -1326,16 +1329,16 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 106, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'buxphgtzqykfawvomcjresnldi'" + "'ypetfugkzdsacbvwjohqlnirmx'" ] }, - "execution_count": 65, + "execution_count": 106, "metadata": {}, "output_type": "execute_result" } @@ -1346,7 +1349,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 107, "metadata": {}, "outputs": [ { @@ -1355,7 +1358,7 @@ "[]" ] }, - "execution_count": 66, + "execution_count": 107, "metadata": {}, "output_type": "execute_result" } @@ -1366,16 +1369,16 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 108, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(10207, 9837)" + "(10207, 9811)" ] }, - "execution_count": 67, + "execution_count": 108, "metadata": {}, "output_type": "execute_result" } @@ -1386,7 +1389,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 109, "metadata": { "collapsed": true }, @@ -1404,8 +1407,10 @@ }, { "cell_type": "code", - "execution_count": 69, - "metadata": {}, + "execution_count": 110, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "simple_lnet = simplify(plnet)" @@ -1413,7 +1418,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 111, "metadata": {}, "outputs": [ { @@ -1422,7 +1427,7 @@ "True" ] }, - "execution_count": 70, + "execution_count": 111, "metadata": {}, "output_type": "execute_result" } @@ -1433,16 +1438,16 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 112, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'buxphgtzqykfawvomcjresnldi'" + "'ypetfugkzdsacbvwjohqlnirmx'" ] }, - "execution_count": 71, + "execution_count": 112, "metadata": {}, "output_type": "execute_result" } @@ -1453,16 +1458,16 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 113, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'buxphgtzqykfawvomcjresnldi'" + "'ypetfugkzdsacbvwjohqlnirmx'" ] }, - "execution_count": 72, + "execution_count": 113, "metadata": {}, "output_type": "execute_result" } @@ -1473,16 +1478,16 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 114, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "9835" + "9809" ] }, - "execution_count": 73, + "execution_count": 114, "metadata": {}, "output_type": "execute_result" } @@ -1493,7 +1498,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 115, "metadata": { "collapsed": true }, @@ -1518,7 +1523,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 116, "metadata": { "collapsed": true }, @@ -1544,7 +1549,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 117, "metadata": {}, "outputs": [ { @@ -1553,7 +1558,7 @@ "[]" ] }, - "execution_count": 76, + "execution_count": 117, "metadata": {}, "output_type": "execute_result" } @@ -1566,7 +1571,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 118, "metadata": { "scrolled": true }, @@ -1577,7 +1582,7 @@ "[]" ] }, - "execution_count": 91, + "execution_count": 118, "metadata": {}, "output_type": "execute_result" } @@ -1593,7 +1598,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 119, "metadata": { "scrolled": true }, @@ -1601,49 +1606,49 @@ { "data": { "text/plain": [ - "[(Link(height=195, left=5, right=10),\n", - " Link(height=197, left=1, right=5),\n", - " Link(height=198, left=5, right=10),\n", - " Link(height=199, left=1, right=5)),\n", - " (Link(height=359, left=6, right=16),\n", - " Link(height=360, left=16, right=20),\n", - " Link(height=361, left=6, right=16),\n", - " Link(height=362, left=16, right=20)),\n", - " (Link(height=409, left=0, right=9),\n", - " Link(height=410, left=9, right=16),\n", - " Link(height=411, left=0, right=9),\n", - " Link(height=412, left=9, right=16)),\n", - " (Link(height=606, left=0, right=7),\n", - " Link(height=607, left=0, right=5),\n", - " Link(height=608, left=0, right=7),\n", - " Link(height=609, left=0, right=5)),\n", - " (Link(height=967, left=7, right=19),\n", - " Link(height=968, left=19, right=23),\n", - " Link(height=969, left=7, right=19),\n", - " Link(height=970, left=19, right=23)),\n", - " (Link(height=973, left=9, right=18),\n", - " Link(height=975, left=9, right=15),\n", - " Link(height=976, left=9, right=18),\n", - " Link(height=977, left=9, right=15)),\n", - " (Link(height=1193, left=1, right=11),\n", - " Link(height=1194, left=1, right=19),\n", - " Link(height=1195, left=1, right=11),\n", - " Link(height=1196, left=1, right=19)),\n", - " (Link(height=1388, left=17, right=21),\n", - " Link(height=1389, left=6, right=17),\n", - " Link(height=1390, left=17, right=21),\n", - " Link(height=1391, left=6, right=17)),\n", - " (Link(height=1700, left=5, right=24),\n", - " Link(height=1701, left=11, right=24),\n", - " Link(height=1702, left=5, right=24),\n", - " Link(height=1703, left=11, right=24)),\n", - " (Link(height=1923, left=12, right=19),\n", - " Link(height=1924, left=19, right=24),\n", - " Link(height=1925, left=12, right=19),\n", - " Link(height=1926, left=19, right=24))]" + "[(Link(height=301, left=7, right=23),\n", + " Link(height=302, left=16, right=23),\n", + " Link(height=303, left=7, right=23),\n", + " Link(height=304, left=16, right=23)),\n", + " (Link(height=362, left=11, right=23),\n", + " Link(height=363, left=3, right=23),\n", + " Link(height=364, left=11, right=23),\n", + " Link(height=365, left=3, right=23)),\n", + " (Link(height=363, left=3, right=23),\n", + " Link(height=364, left=11, right=23),\n", + " Link(height=365, left=3, right=23),\n", + " Link(height=366, left=11, right=23)),\n", + " (Link(height=595, left=12, right=15),\n", + " Link(height=596, left=10, right=15),\n", + " Link(height=597, left=12, right=15),\n", + " Link(height=598, left=10, right=15)),\n", + " (Link(height=796, left=12, right=21),\n", + " Link(height=797, left=4, right=12),\n", + " Link(height=798, left=12, right=21),\n", + " Link(height=799, left=4, right=12)),\n", + " (Link(height=879, left=0, right=18),\n", + " Link(height=880, left=0, right=8),\n", + " Link(height=881, left=0, right=18),\n", + " Link(height=882, left=0, right=8)),\n", + " (Link(height=930, left=3, right=17),\n", + " Link(height=931, left=3, right=21),\n", + " Link(height=932, left=3, right=17),\n", + " Link(height=933, left=3, right=21)),\n", + " (Link(height=1120, left=5, right=19),\n", + " Link(height=1121, left=18, right=19),\n", + " Link(height=1122, left=5, right=19),\n", + " Link(height=1123, left=18, right=19)),\n", + " (Link(height=2040, left=9, right=21),\n", + " Link(height=2041, left=9, right=15),\n", + " Link(height=2042, left=9, right=21),\n", + " Link(height=2043, left=9, right=15)),\n", + " (Link(height=2110, left=13, right=21),\n", + " Link(height=2111, left=13, right=24),\n", + " Link(height=2112, left=13, right=21),\n", + " Link(height=2113, left=13, right=24))]" ] }, - "execution_count": 92, + "execution_count": 119, "metadata": {}, "output_type": "execute_result" } @@ -1659,7 +1664,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 120, "metadata": { "scrolled": true }, @@ -1667,217 +1672,209 @@ { "data": { "text/plain": [ - "[(Link(height=8, left=1, right=5),\n", - " Link(height=9, left=1, right=21),\n", - " Link(height=10, left=1, right=5),\n", - " Link(height=11, left=1, right=21)),\n", - " (Link(height=40, left=16, right=23),\n", - " Link(height=41, left=16, right=19),\n", - " Link(height=42, left=16, right=23),\n", - " Link(height=43, left=16, right=19)),\n", - " (Link(height=62, left=0, right=10),\n", - " Link(height=63, left=10, right=13),\n", - " Link(height=64, left=0, right=10),\n", - " Link(height=65, left=10, right=13)),\n", - " (Link(height=137, left=23, right=24),\n", - " Link(height=139, left=0, right=24),\n", - " Link(height=140, left=23, right=24),\n", - " Link(height=141, left=0, right=24)),\n", - " (Link(height=138, left=10, right=21),\n", - " Link(height=139, left=2, right=10),\n", - " Link(height=140, left=10, right=21),\n", - " Link(height=141, left=2, right=10)),\n", - " (Link(height=139, left=2, right=10),\n", - " Link(height=140, left=10, right=21),\n", - " Link(height=141, left=2, right=10),\n", - " Link(height=142, left=10, right=21)),\n", - " (Link(height=156, left=6, right=11),\n", - " Link(height=157, left=3, right=6),\n", - " Link(height=158, left=6, right=11),\n", - " Link(height=159, left=3, right=6)),\n", - " (Link(height=184, left=2, right=21),\n", - " Link(height=185, left=5, right=21),\n", - " Link(height=186, left=2, right=21),\n", - " Link(height=187, left=5, right=21)),\n", - " (Link(height=274, left=7, right=13),\n", - " Link(height=275, left=7, right=11),\n", - " Link(height=276, left=7, right=13),\n", - " Link(height=277, left=7, right=11)),\n", - " (Link(height=292, left=14, right=15),\n", - " Link(height=293, left=5, right=15),\n", - " Link(height=294, left=14, right=15),\n", - " Link(height=295, left=5, right=15)),\n", - " (Link(height=389, left=1, right=8),\n", - " Link(height=391, left=8, right=15),\n", - " Link(height=392, left=1, right=8),\n", - " Link(height=393, left=8, right=15)),\n", - " (Link(height=422, left=14, right=22),\n", - " Link(height=424, left=14, right=18),\n", - " Link(height=425, left=14, right=22),\n", - " Link(height=426, left=14, right=18)),\n", - " (Link(height=434, left=5, right=19),\n", - " Link(height=435, left=1, right=19),\n", - " Link(height=436, left=5, right=19),\n", - " Link(height=437, left=1, right=19)),\n", - " (Link(height=456, left=0, right=15),\n", - " Link(height=457, left=14, right=15),\n", - " Link(height=458, left=0, right=15),\n", - " Link(height=459, left=14, right=15)),\n", - " (Link(height=550, left=13, right=21),\n", - " Link(height=551, left=6, right=21),\n", - " Link(height=552, left=13, right=21),\n", - " Link(height=553, left=6, right=21)),\n", - " (Link(height=624, left=17, right=23),\n", - " Link(height=625, left=1, right=23),\n", - " Link(height=626, left=17, right=23),\n", - " Link(height=627, left=1, right=23)),\n", - " (Link(height=703, left=8, right=15),\n", - " Link(height=704, left=3, right=15),\n", - " Link(height=705, left=8, right=15),\n", - " Link(height=706, left=3, right=15)),\n", - " (Link(height=794, left=7, right=24),\n", - " Link(height=795, left=8, right=24),\n", - " Link(height=796, left=7, right=24),\n", - " Link(height=797, left=8, right=24)),\n", - " (Link(height=800, left=8, right=13),\n", - " Link(height=801, left=4, right=8),\n", - " Link(height=802, left=8, right=13),\n", - " Link(height=803, left=4, right=8)),\n", - " (Link(height=814, left=16, right=17),\n", - " Link(height=815, left=3, right=16),\n", - " Link(height=816, left=16, right=17),\n", - " Link(height=817, left=3, right=16)),\n", - " (Link(height=905, left=2, right=15),\n", - " Link(height=906, left=13, right=15),\n", - " Link(height=907, left=2, right=15),\n", - " Link(height=908, left=13, right=15)),\n", - " (Link(height=926, left=2, right=15),\n", - " Link(height=927, left=15, right=16),\n", - " Link(height=928, left=2, right=15),\n", - " Link(height=929, left=15, right=16)),\n", - " (Link(height=967, left=2, right=15),\n", - " Link(height=968, left=2, right=14),\n", - " Link(height=969, left=2, right=15),\n", - " Link(height=970, left=2, right=14)),\n", - " (Link(height=982, left=13, right=18),\n", - " Link(height=985, left=18, right=19),\n", - " Link(height=986, left=13, right=18),\n", - " Link(height=987, left=18, right=19)),\n", - " (Link(height=993, left=5, right=16),\n", - " Link(height=994, left=2, right=5),\n", - " Link(height=995, left=5, right=16),\n", - " Link(height=996, left=2, right=5)),\n", - " (Link(height=1058, left=9, right=24),\n", - " Link(height=1062, left=9, right=18),\n", - " Link(height=1063, left=9, right=24),\n", - " Link(height=1064, left=9, right=18)),\n", - " (Link(height=1171, left=11, right=21),\n", - " Link(height=1172, left=11, right=14),\n", - " Link(height=1173, left=11, right=21),\n", - " Link(height=1174, left=11, right=14)),\n", - " (Link(height=1294, left=0, right=11),\n", - " Link(height=1295, left=0, right=14),\n", - " Link(height=1296, left=0, right=11),\n", - " Link(height=1297, left=0, right=14)),\n", - " (Link(height=1341, left=4, right=9),\n", - " Link(height=1343, left=4, right=10),\n", - " Link(height=1344, left=4, right=9),\n", - " Link(height=1345, left=4, right=10)),\n", - " (Link(height=1342, left=12, right=18),\n", - " Link(height=1343, left=12, right=24),\n", - " Link(height=1344, left=12, right=18),\n", - " Link(height=1345, left=12, right=24)),\n", - " (Link(height=1353, left=0, right=17),\n", - " Link(height=1354, left=0, right=23),\n", - " Link(height=1355, left=0, right=17),\n", - " Link(height=1356, left=0, right=23)),\n", - " (Link(height=1367, left=4, right=16),\n", - " Link(height=1368, left=16, right=17),\n", - " Link(height=1369, left=4, right=16),\n", - " Link(height=1370, left=16, right=17)),\n", - " (Link(height=1441, left=11, right=24),\n", - " Link(height=1442, left=18, right=24),\n", - " Link(height=1443, left=11, right=24),\n", - " Link(height=1444, left=18, right=24)),\n", - " (Link(height=1451, left=6, right=20),\n", - " Link(height=1453, left=16, right=20),\n", - " Link(height=1454, left=6, right=20),\n", - " Link(height=1455, left=16, right=20)),\n", - " (Link(height=1474, left=17, right=23),\n", - " Link(height=1475, left=3, right=17),\n", - " Link(height=1476, left=17, right=23),\n", - " Link(height=1477, left=3, right=17)),\n", - " (Link(height=1550, left=8, right=23),\n", - " Link(height=1551, left=7, right=23),\n", - " Link(height=1552, left=8, right=23),\n", - " Link(height=1553, left=7, right=23)),\n", - " (Link(height=1574, left=4, right=14),\n", - " Link(height=1575, left=14, right=23),\n", - " Link(height=1576, left=4, right=14),\n", - " Link(height=1577, left=14, right=23)),\n", - " (Link(height=1580, left=0, right=1),\n", - " Link(height=1581, left=1, right=21),\n", - " Link(height=1582, left=0, right=1),\n", - " Link(height=1583, left=1, right=21)),\n", - " (Link(height=1612, left=15, right=22),\n", - " Link(height=1617, left=7, right=15),\n", - " Link(height=1618, left=15, right=22),\n", - " Link(height=1619, left=7, right=15)),\n", - " (Link(height=1644, left=12, right=18),\n", - " Link(height=1646, left=12, right=20),\n", - " Link(height=1647, left=12, right=18),\n", - " Link(height=1648, left=12, right=20)),\n", - " (Link(height=1716, left=13, right=24),\n", - " Link(height=1719, left=14, right=24),\n", - " Link(height=1720, left=13, right=24),\n", - " Link(height=1721, left=14, right=24)),\n", - " (Link(height=1735, left=3, right=24),\n", - " Link(height=1736, left=3, right=21),\n", - " Link(height=1737, left=3, right=24),\n", - " Link(height=1738, left=3, right=21)),\n", - " (Link(height=1736, left=3, right=21),\n", - " Link(height=1737, left=3, right=24),\n", - " Link(height=1738, left=3, right=21),\n", - " Link(height=1739, left=3, right=24)),\n", - " (Link(height=1776, left=0, right=21),\n", - " Link(height=1777, left=13, right=21),\n", - " Link(height=1778, left=0, right=21),\n", - " Link(height=1779, left=13, right=21)),\n", - " (Link(height=1783, left=7, right=9),\n", - " Link(height=1784, left=7, right=12),\n", - " Link(height=1785, left=7, right=9),\n", - " Link(height=1786, left=7, right=12)),\n", - " (Link(height=1929, left=10, right=24),\n", - " Link(height=1930, left=8, right=24),\n", - " Link(height=1931, left=10, right=24),\n", - " Link(height=1932, left=8, right=24)),\n", - " (Link(height=1935, left=4, right=23),\n", - " Link(height=1936, left=3, right=4),\n", - " Link(height=1937, left=4, right=23),\n", - " Link(height=1938, left=3, right=4)),\n", - " (Link(height=2043, left=4, right=7),\n", - " Link(height=2044, left=7, right=15),\n", - " Link(height=2045, left=4, right=7),\n", - " Link(height=2046, left=7, right=15)),\n", - " (Link(height=2045, left=8, right=19),\n", - " Link(height=2051, left=8, right=15),\n", - " Link(height=2052, left=8, right=19),\n", - " Link(height=2053, left=8, right=15)),\n", - " (Link(height=2172, left=10, right=15),\n", - " Link(height=2173, left=10, right=16),\n", - " Link(height=2174, left=10, right=15),\n", - " Link(height=2175, left=10, right=16)),\n", - " (Link(height=2214, left=22, right=24),\n", - " Link(height=2215, left=7, right=22),\n", - " Link(height=2216, left=22, right=24),\n", - " Link(height=2217, left=7, right=22)),\n", - " (Link(height=2231, left=5, right=6),\n", - " Link(height=2232, left=6, right=14),\n", - " Link(height=2233, left=5, right=6),\n", - " Link(height=2234, left=6, right=14))]" + "[(Link(height=49, left=10, right=20),\n", + " Link(height=50, left=2, right=20),\n", + " Link(height=51, left=10, right=20),\n", + " Link(height=52, left=2, right=20)),\n", + " (Link(height=54, left=2, right=24),\n", + " Link(height=55, left=3, right=24),\n", + " Link(height=56, left=2, right=24),\n", + " Link(height=57, left=3, right=24)),\n", + " (Link(height=62, left=2, right=15),\n", + " Link(height=63, left=0, right=15),\n", + " Link(height=64, left=2, right=15),\n", + " Link(height=65, left=0, right=15)),\n", + " (Link(height=114, left=14, right=18),\n", + " Link(height=115, left=3, right=18),\n", + " Link(height=116, left=14, right=18),\n", + " Link(height=117, left=3, right=18)),\n", + " (Link(height=138, left=13, right=19),\n", + " Link(height=139, left=8, right=19),\n", + " Link(height=140, left=13, right=19),\n", + " Link(height=141, left=8, right=19)),\n", + " (Link(height=160, left=12, right=13),\n", + " Link(height=161, left=4, right=12),\n", + " Link(height=162, left=12, right=13),\n", + " Link(height=163, left=4, right=12)),\n", + " (Link(height=315, left=23, right=24),\n", + " Link(height=320, left=20, right=23),\n", + " Link(height=321, left=23, right=24),\n", + " Link(height=322, left=20, right=23)),\n", + " (Link(height=324, left=3, right=18),\n", + " Link(height=325, left=16, right=18),\n", + " Link(height=326, left=3, right=18),\n", + " Link(height=327, left=16, right=18)),\n", + " (Link(height=342, left=21, right=22),\n", + " Link(height=345, left=1, right=22),\n", + " Link(height=346, left=21, right=22),\n", + " Link(height=347, left=1, right=22)),\n", + " (Link(height=405, left=8, right=19),\n", + " Link(height=406, left=4, right=8),\n", + " Link(height=407, left=8, right=19),\n", + " Link(height=408, left=4, right=8)),\n", + " (Link(height=468, left=11, right=22),\n", + " Link(height=469, left=15, right=22),\n", + " Link(height=470, left=11, right=22),\n", + " Link(height=471, left=15, right=22)),\n", + " (Link(height=549, left=1, right=2),\n", + " Link(height=550, left=1, right=6),\n", + " Link(height=551, left=1, right=2),\n", + " Link(height=552, left=1, right=6)),\n", + " (Link(height=568, left=16, right=21),\n", + " Link(height=569, left=11, right=21),\n", + " Link(height=570, left=16, right=21),\n", + " Link(height=571, left=11, right=21)),\n", + " (Link(height=608, left=17, right=20),\n", + " Link(height=609, left=2, right=17),\n", + " Link(height=610, left=17, right=20),\n", + " Link(height=611, left=2, right=17)),\n", + " (Link(height=613, left=18, right=21),\n", + " Link(height=618, left=18, right=19),\n", + " Link(height=619, left=18, right=21),\n", + " Link(height=620, left=18, right=19)),\n", + " (Link(height=635, left=2, right=4),\n", + " Link(height=636, left=4, right=20),\n", + " Link(height=637, left=2, right=4),\n", + " Link(height=638, left=4, right=20)),\n", + " (Link(height=681, left=7, right=20),\n", + " Link(height=682, left=20, right=22),\n", + " Link(height=683, left=7, right=20),\n", + " Link(height=684, left=20, right=22)),\n", + " (Link(height=750, left=23, right=24),\n", + " Link(height=751, left=18, right=24),\n", + " Link(height=752, left=23, right=24),\n", + " Link(height=753, left=18, right=24)),\n", + " (Link(height=760, left=12, right=18),\n", + " Link(height=761, left=17, right=18),\n", + " Link(height=762, left=12, right=18),\n", + " Link(height=763, left=17, right=18)),\n", + " (Link(height=765, left=0, right=9),\n", + " Link(height=766, left=0, right=14),\n", + " Link(height=767, left=0, right=9),\n", + " Link(height=768, left=0, right=14)),\n", + " (Link(height=805, left=16, right=22),\n", + " Link(height=806, left=0, right=16),\n", + " Link(height=807, left=16, right=22),\n", + " Link(height=808, left=0, right=16)),\n", + " (Link(height=834, left=1, right=6),\n", + " Link(height=835, left=3, right=6),\n", + " Link(height=836, left=1, right=6),\n", + " Link(height=837, left=3, right=6)),\n", + " (Link(height=881, left=2, right=12),\n", + " Link(height=882, left=2, right=23),\n", + " Link(height=883, left=2, right=12),\n", + " Link(height=884, left=2, right=23)),\n", + " (Link(height=904, left=12, right=23),\n", + " Link(height=905, left=12, right=14),\n", + " Link(height=906, left=12, right=23),\n", + " Link(height=907, left=12, right=14)),\n", + " (Link(height=936, left=7, right=17),\n", + " Link(height=937, left=15, right=17),\n", + " Link(height=938, left=7, right=17),\n", + " Link(height=939, left=15, right=17)),\n", + " (Link(height=1010, left=4, right=6),\n", + " Link(height=1011, left=6, right=17),\n", + " Link(height=1012, left=4, right=6),\n", + " Link(height=1013, left=6, right=17)),\n", + " (Link(height=1030, left=1, right=12),\n", + " Link(height=1031, left=1, right=20),\n", + " Link(height=1032, left=1, right=12),\n", + " Link(height=1033, left=1, right=20)),\n", + " (Link(height=1197, left=2, right=9),\n", + " Link(height=1198, left=9, right=22),\n", + " Link(height=1199, left=2, right=9),\n", + " Link(height=1200, left=9, right=22)),\n", + " (Link(height=1222, left=2, right=3),\n", + " Link(height=1223, left=2, right=5),\n", + " Link(height=1224, left=2, right=3),\n", + " Link(height=1225, left=2, right=5)),\n", + " (Link(height=1318, left=12, right=23),\n", + " Link(height=1319, left=4, right=12),\n", + " Link(height=1320, left=12, right=23),\n", + " Link(height=1321, left=4, right=12)),\n", + " (Link(height=1341, left=17, right=22),\n", + " Link(height=1342, left=11, right=17),\n", + " Link(height=1343, left=17, right=22),\n", + " Link(height=1344, left=11, right=17)),\n", + " (Link(height=1396, left=4, right=9),\n", + " Link(height=1397, left=3, right=9),\n", + " Link(height=1398, left=4, right=9),\n", + " Link(height=1399, left=3, right=9)),\n", + " (Link(height=1426, left=18, right=24),\n", + " Link(height=1427, left=17, right=18),\n", + " Link(height=1428, left=18, right=24),\n", + " Link(height=1429, left=17, right=18)),\n", + " (Link(height=1456, left=2, right=15),\n", + " Link(height=1457, left=3, right=15),\n", + " Link(height=1458, left=2, right=15),\n", + " Link(height=1459, left=3, right=15)),\n", + " (Link(height=1505, left=13, right=18),\n", + " Link(height=1506, left=13, right=21),\n", + " Link(height=1507, left=13, right=18),\n", + " Link(height=1508, left=13, right=21)),\n", + " (Link(height=1551, left=10, right=12),\n", + " Link(height=1552, left=4, right=12),\n", + " Link(height=1553, left=10, right=12),\n", + " Link(height=1554, left=4, right=12)),\n", + " (Link(height=1622, left=4, right=11),\n", + " Link(height=1623, left=11, right=16),\n", + " Link(height=1624, left=4, right=11),\n", + " Link(height=1625, left=11, right=16)),\n", + " (Link(height=1653, left=8, right=24),\n", + " Link(height=1654, left=4, right=8),\n", + " Link(height=1655, left=8, right=24),\n", + " Link(height=1656, left=4, right=8)),\n", + " (Link(height=1688, left=0, right=5),\n", + " Link(height=1689, left=0, right=23),\n", + " Link(height=1690, left=0, right=5),\n", + " Link(height=1691, left=0, right=23)),\n", + " (Link(height=1724, left=10, right=23),\n", + " Link(height=1725, left=10, right=11),\n", + " Link(height=1726, left=10, right=23),\n", + " Link(height=1727, left=10, right=11)),\n", + " (Link(height=1863, left=1, right=12),\n", + " Link(height=1864, left=1, right=13),\n", + " Link(height=1865, left=1, right=12),\n", + " Link(height=1866, left=1, right=13)),\n", + " (Link(height=1873, left=10, right=22),\n", + " Link(height=1874, left=10, right=15),\n", + " Link(height=1875, left=10, right=22),\n", + " Link(height=1876, left=10, right=15)),\n", + " (Link(height=1879, left=18, right=20),\n", + " Link(height=1880, left=17, right=20),\n", + " Link(height=1881, left=18, right=20),\n", + " Link(height=1882, left=17, right=20)),\n", + " (Link(height=1916, left=18, right=19),\n", + " Link(height=1917, left=7, right=18),\n", + " Link(height=1918, left=18, right=19),\n", + " Link(height=1919, left=7, right=18)),\n", + " (Link(height=1961, left=11, right=20),\n", + " Link(height=1962, left=7, right=20),\n", + " Link(height=1963, left=11, right=20),\n", + " Link(height=1964, left=7, right=20)),\n", + " (Link(height=1962, left=9, right=18),\n", + " Link(height=1963, left=18, right=19),\n", + " Link(height=1964, left=9, right=18),\n", + " Link(height=1965, left=18, right=19)),\n", + " (Link(height=2031, left=3, right=6),\n", + " Link(height=2032, left=3, right=4),\n", + " Link(height=2033, left=3, right=6),\n", + " Link(height=2034, left=3, right=4)),\n", + " (Link(height=2077, left=2, right=9),\n", + " Link(height=2078, left=2, right=23),\n", + " Link(height=2079, left=2, right=9),\n", + " Link(height=2080, left=2, right=23)),\n", + " (Link(height=2165, left=1, right=8),\n", + " Link(height=2166, left=4, right=8),\n", + " Link(height=2167, left=1, right=8),\n", + " Link(height=2168, left=4, right=8)),\n", + " (Link(height=2185, left=6, right=21),\n", + " Link(height=2186, left=11, right=21),\n", + " Link(height=2187, left=6, right=21),\n", + " Link(height=2188, left=11, right=21))]" ] }, - "execution_count": 93, + "execution_count": 120, "metadata": {}, "output_type": "execute_result" } @@ -1895,7 +1892,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 121, "metadata": {}, "outputs": [ { @@ -1904,7 +1901,7 @@ "True" ] }, - "execution_count": 94, + "execution_count": 121, "metadata": {}, "output_type": "execute_result" } @@ -1915,7 +1912,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 122, "metadata": { "scrolled": true }, @@ -1923,10 +1920,10 @@ { "data": { "text/plain": [ - "9931" + "9909" ] }, - "execution_count": 95, + "execution_count": 122, "metadata": {}, "output_type": "execute_result" } @@ -1938,16 +1935,16 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 123, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(9835, 10135, 9931)" + "(9809, 10109, 9909)" ] }, - "execution_count": 96, + "execution_count": 123, "metadata": {}, "output_type": "execute_result" } @@ -1958,7 +1955,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 124, "metadata": {}, "outputs": [ { @@ -1967,7 +1964,7 @@ "True" ] }, - "execution_count": 97, + "execution_count": 124, "metadata": {}, "output_type": "execute_result" } @@ -1978,7 +1975,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 125, "metadata": {}, "outputs": [ { @@ -1987,7 +1984,7 @@ "True" ] }, - "execution_count": 98, + "execution_count": 125, "metadata": {}, "output_type": "execute_result" } @@ -1998,16 +1995,16 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 126, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2286" + "2285" ] }, - "execution_count": 99, + "execution_count": 126, "metadata": {}, "output_type": "execute_result" } @@ -2018,7 +2015,7 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 127, "metadata": { "collapsed": true }, @@ -2059,7 +2056,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 128, "metadata": { "scrolled": true }, @@ -2162,10 +2159,6 @@ "triple ok\n", "pairs ok\n", "triple ok\n", - "pairs ok\n", - "triple ok\n", - "pairs ok\n", - "triple ok\n", "** done\n" ] } @@ -2176,7 +2169,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 129, "metadata": {}, "outputs": [ { @@ -2185,7 +2178,7 @@ "True" ] }, - "execution_count": 102, + "execution_count": 129, "metadata": {}, "output_type": "execute_result" } @@ -2196,16 +2189,16 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 130, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "10135" + "10109" ] }, - "execution_count": 103, + "execution_count": 130, "metadata": {}, "output_type": "execute_result" } @@ -2216,42 +2209,275 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 131, + "metadata": {}, + "outputs": [], + "source": [ + "# open('04-lines.txt', 'w').write(show_net(lnettp, randomise=True, pair_sep='\\n'))" + ] + }, + { + "cell_type": "code", + "execution_count": 114, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "83459" + "139" ] }, - "execution_count": 113, + "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "open('04-lines.txt', 'w').write(show_net(lnettp, randomise=True, pair_sep='\\n'))" + "# open('04-small.txt', 'w').write(show_net(make_net(20), randomise=True, pair_sep='\\n'))" ] }, { "cell_type": "code", - "execution_count": 114, + "execution_count": 143, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8 [(2, 4), (0, 4), (2, 4), (0, 4)]\n", + "10 [(1, 2), (1, 2)]\n" + ] + }, + { + "data": { + "text/plain": [ + "[Link(height=0, left=2, right=5),\n", + " Link(height=1, left=1, right=4),\n", + " Link(height=2, left=0, right=3),\n", + " Link(height=3, left=0, right=3),\n", + " Link(height=4, left=0, right=5),\n", + " Link(height=5, left=3, right=5),\n", + " Link(height=6, left=0, right=2),\n", + " Link(height=7, left=3, right=4),\n", + " Link(height=8, left=2, right=4),\n", + " Link(height=9, left=1, right=2),\n", + " Link(height=10, left=0, right=4),\n", + " Link(height=11, left=1, right=2),\n", + " Link(height=12, left=2, right=4),\n", + " Link(height=13, left=1, right=2),\n", + " Link(height=14, left=0, right=4),\n", + " Link(height=15, left=1, right=4)]" + ] + }, + "execution_count": 143, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net = make_net(10, lines=6)\n", + "net = add_triple_pair(net, trace=True)\n", + "net = add_pair(net, trace=True)\n", + "net = read_net(show_net(net, randomise=True))\n", + "net" + ] + }, + { + "cell_type": "code", + "execution_count": 147, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "139" + "'(2, 5), (1, 4), (0, 3), (0, 3), (0, 5), (3, 5), (0, 2), (3, 4), (2, 4), (1, 2), (0, 4), (1, 2), (2, 4), (1, 2), (0, 4), (1, 4)'" ] }, - "execution_count": 114, + "execution_count": 147, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "show_net(net)" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Link(height=0, left=2, right=5),\n", + " Link(height=1, left=1, right=4),\n", + " Link(height=2, left=0, right=3),\n", + " Link(height=3, left=0, right=3),\n", + " Link(height=4, left=0, right=5),\n", + " Link(height=5, left=3, right=5),\n", + " Link(height=6, left=0, right=2),\n", + " Link(height=7, left=3, right=4),\n", + " Link(height=8, left=2, right=4),\n", + " Link(height=9, left=1, right=2),\n", + " Link(height=10, left=0, right=4),\n", + " Link(height=11, left=1, right=2),\n", + " Link(height=12, left=2, right=4),\n", + " Link(height=13, left=0, right=4),\n", + " Link(height=14, left=1, right=4)]" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net = read_net('(2, 5), (1, 4), (0, 3), (0, 3), (0, 5), (3, 5), (0, 2), (3, 4), (2, 4), (1, 2), (0, 4), (1, 2), (2, 4), (0, 4), (1, 4)')\n", + "net" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Link(height=0, left=0, right=3),\n", + " Link(height=0, left=1, right=4),\n", + " Link(height=0, left=2, right=5),\n", + " Link(height=1, left=0, right=3),\n", + " Link(height=2, left=0, right=5),\n", + " Link(height=3, left=0, right=2),\n", + " Link(height=3, left=3, right=5),\n", + " Link(height=4, left=3, right=4),\n", + " Link(height=5, left=2, right=4),\n", + " Link(height=6, left=0, right=4),\n", + " Link(height=6, left=1, right=2),\n", + " Link(height=7, left=1, right=2),\n", + " Link(height=8, left=2, right=4),\n", + " Link(height=9, left=0, right=4),\n", + " Link(height=10, left=1, right=4)]" + ] + }, + "execution_count": 150, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pack(net)" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Link(height=0, left=1, right=4),\n", + " Link(height=0, left=2, right=5),\n", + " Link(height=1, left=0, right=5),\n", + " Link(height=2, left=0, right=2),\n", + " Link(height=2, left=3, right=5),\n", + " Link(height=3, left=3, right=4),\n", + " Link(height=4, left=2, right=4),\n", + " Link(height=5, left=0, right=4),\n", + " Link(height=6, left=2, right=4),\n", + " Link(height=7, left=0, right=4),\n", + " Link(height=8, left=1, right=4)]" + ] + }, + "execution_count": 151, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "epnet = eliminate_pairs(net)\n", + "pack(epnet)" + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11\n", + "11\n" + ] + }, + { + "data": { + "text/plain": [ + "[Link(height=0, left=1, right=4),\n", + " Link(height=0, left=2, right=5),\n", + " Link(height=1, left=0, right=5),\n", + " Link(height=2, left=0, right=2),\n", + " Link(height=2, left=3, right=5),\n", + " Link(height=3, left=3, right=4),\n", + " Link(height=4, left=0, right=4),\n", + " Link(height=5, left=2, right=4),\n", + " Link(height=6, left=1, right=4)]" + ] + }, + "execution_count": 152, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eptnet = eliminate_triple_pairs(epnet)\n", + "pack(eptnet)" + ] + }, + { + "cell_type": "code", + "execution_count": 153, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 153, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "''.join(follow_many(string.ascii_lowercase, net)) == ''.join(follow_many(string.ascii_lowercase, eptnet))" + ] + }, + { + "cell_type": "code", + "execution_count": 155, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "104" + ] + }, + "execution_count": 155, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "open('04-small.txt', 'w').write(show_net(make_net(20), randomise=True, pair_sep='\\n'))" + "open('04-small.txt', 'w').write(show_net(net, pair_sep='\\n'))" ] }, { diff --git a/04-08-amidakuji/amidakuji-solution-1.ipynb b/04-08-amidakuji/amidakuji-solution-1.ipynb index d9a9249..7f149b4 100644 --- a/04-08-amidakuji/amidakuji-solution-1.ipynb +++ b/04-08-amidakuji/amidakuji-solution-1.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 27, "metadata": { "collapsed": true }, @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 28, "metadata": { "collapsed": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 29, "metadata": { "collapsed": true }, @@ -39,7 +39,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 30, "metadata": { "collapsed": true }, @@ -51,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 31, "metadata": { "collapsed": true }, @@ -67,35 +67,30 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[Link(height=0, left=2, right=3),\n", - " Link(height=1, left=2, right=6),\n", - " Link(height=2, left=3, right=7),\n", - " Link(height=3, left=5, right=6),\n", - " Link(height=4, left=0, right=1),\n", - " Link(height=5, left=0, right=1),\n", - " Link(height=6, left=6, right=7),\n", - " Link(height=7, left=2, right=5),\n", - " Link(height=8, left=6, right=9),\n", - " Link(height=9, left=4, right=8),\n", - " Link(height=10, left=0, right=2),\n", - " Link(height=11, left=5, right=7),\n", - " Link(height=12, left=4, right=8),\n", - " Link(height=13, left=1, right=5),\n", - " Link(height=14, left=6, right=8),\n", - " Link(height=15, left=6, right=9),\n", - " Link(height=16, left=2, right=5),\n", - " Link(height=17, left=1, right=8),\n", - " Link(height=18, left=5, right=7),\n", - " Link(height=19, left=2, right=9)]" + "[Link(height=0, left=2, right=5),\n", + " Link(height=1, left=1, right=4),\n", + " Link(height=2, left=0, right=3),\n", + " Link(height=3, left=0, right=3),\n", + " Link(height=4, left=0, right=5),\n", + " Link(height=5, left=3, right=5),\n", + " Link(height=6, left=0, right=2),\n", + " Link(height=7, left=3, right=4),\n", + " Link(height=8, left=2, right=4),\n", + " Link(height=9, left=1, right=2),\n", + " Link(height=10, left=0, right=4),\n", + " Link(height=11, left=1, right=2),\n", + " Link(height=12, left=2, right=4),\n", + " Link(height=13, left=0, right=4),\n", + " Link(height=14, left=1, right=4)]" ] }, - "execution_count": 6, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -107,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -116,7 +111,7 @@ "10135" ] }, - "execution_count": 7, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -128,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 34, "metadata": { "collapsed": true }, @@ -140,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 35, "metadata": { "collapsed": true }, @@ -152,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 36, "metadata": { "collapsed": true }, @@ -171,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 37, "metadata": { "collapsed": true }, @@ -190,16 +185,16 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "19" + "14" ] }, - "execution_count": 12, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -210,16 +205,16 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "7" + "10" ] }, - "execution_count": 13, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -230,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -239,7 +234,7 @@ "10134" ] }, - "execution_count": 14, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -250,8 +245,10 @@ }, { "cell_type": "code", - "execution_count": 15, - "metadata": {}, + "execution_count": 41, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "pnet = pack(net)" @@ -259,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -268,7 +265,7 @@ "2286" ] }, - "execution_count": 16, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -279,7 +276,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 43, "metadata": { "collapsed": true }, @@ -291,7 +288,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 44, "metadata": { "collapsed": true }, @@ -308,34 +305,34 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'djihegcafb'" + "'acfbed'" ] }, - "execution_count": 19, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "''.join(follow_many('abcdefghij', small_net))" + "''.join(follow_many('abcdef', small_net))" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 46, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10000 loops, best of 3: 50.4 µs per loop\n" + "10000 loops, best of 3: 39.5 µs per loop\n" ] } ], @@ -346,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -355,7 +352,7 @@ "'doqzmbishkwunvltpcexyjgfra'" ] }, - "execution_count": 21, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -366,14 +363,14 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 48, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10 loops, best of 3: 21 ms per loop\n" + "10 loops, best of 3: 19.7 ms per loop\n" ] } ], @@ -382,6 +379,24 @@ "follow_many(string.ascii_lowercase, net)" ] }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100 loops, best of 3: 18.6 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "follow_many(string.ascii_lowercase, pnet)" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/04-08-amidakuji/amidakuji-solution-2.ipynb b/04-08-amidakuji/amidakuji-solution-2.ipynb index 8fc722f..3bc37db 100644 --- a/04-08-amidakuji/amidakuji-solution-2.ipynb +++ b/04-08-amidakuji/amidakuji-solution-2.ipynb @@ -73,26 +73,21 @@ { "data": { "text/plain": [ - "[Link(height=0, left=2, right=3),\n", - " Link(height=1, left=2, right=6),\n", - " Link(height=2, left=3, right=7),\n", - " Link(height=3, left=5, right=6),\n", - " Link(height=4, left=0, right=1),\n", - " Link(height=5, left=0, right=1),\n", - " Link(height=6, left=6, right=7),\n", - " Link(height=7, left=2, right=5),\n", - " Link(height=8, left=6, right=9),\n", - " Link(height=9, left=4, right=8),\n", - " Link(height=10, left=0, right=2),\n", - " Link(height=11, left=5, right=7),\n", - " Link(height=12, left=4, right=8),\n", - " Link(height=13, left=1, right=5),\n", - " Link(height=14, left=6, right=8),\n", - " Link(height=15, left=6, right=9),\n", - " Link(height=16, left=2, right=5),\n", - " Link(height=17, left=1, right=8),\n", - " Link(height=18, left=5, right=7),\n", - " Link(height=19, left=2, right=9)]" + "[Link(height=0, left=2, right=5),\n", + " Link(height=1, left=1, right=4),\n", + " Link(height=2, left=0, right=3),\n", + " Link(height=3, left=0, right=3),\n", + " Link(height=4, left=0, right=5),\n", + " Link(height=5, left=3, right=5),\n", + " Link(height=6, left=0, right=2),\n", + " Link(height=7, left=3, right=4),\n", + " Link(height=8, left=2, right=4),\n", + " Link(height=9, left=1, right=2),\n", + " Link(height=10, left=0, right=4),\n", + " Link(height=11, left=1, right=2),\n", + " Link(height=12, left=2, right=4),\n", + " Link(height=13, left=0, right=4),\n", + " Link(height=14, left=1, right=4)]" ] }, "execution_count": 6, @@ -196,7 +191,7 @@ { "data": { "text/plain": [ - "19" + "14" ] }, "execution_count": 12, @@ -216,7 +211,7 @@ { "data": { "text/plain": [ - "7" + "10" ] }, "execution_count": 13, @@ -305,7 +300,7 @@ { "data": { "text/plain": [ - "'djihegcafb'" + "'acfbedghij'" ] }, "execution_count": 18, @@ -326,7 +321,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "10000 loops, best of 3: 50.2 µs per loop\n" + "10000 loops, best of 3: 38.1 µs per loop\n" ] } ], @@ -364,7 +359,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "10 loops, best of 3: 20.7 ms per loop\n" + "100 loops, best of 3: 19 ms per loop\n" ] } ], @@ -488,7 +483,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "10 loops, best of 3: 26.4 ms per loop\n" + "10 loops, best of 3: 23.5 ms per loop\n" ] } ], @@ -564,7 +559,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1 loop, best of 3: 2.37 s per loop\n" + "1 loop, best of 3: 2.35 s per loop\n" ] } ], diff --git a/04-08-amidakuji/small-expanded-trace.svg b/04-08-amidakuji/small-expanded-trace.svg new file mode 100644 index 0000000..3bed4a4 --- /dev/null +++ b/04-08-amidakuji/small-expanded-trace.svg @@ -0,0 +1,555 @@ + +image/svg+xml0 +1 +2 +3 +4 +5 + \ No newline at end of file diff --git a/04-08-amidakuji/small-expanded-trace.svg.png b/04-08-amidakuji/small-expanded-trace.svg.png new file mode 100644 index 0000000..7328878 Binary files /dev/null and b/04-08-amidakuji/small-expanded-trace.svg.png differ diff --git a/04-08-amidakuji/small-expanded.svg b/04-08-amidakuji/small-expanded.svg new file mode 100644 index 0000000..2c4b4be --- /dev/null +++ b/04-08-amidakuji/small-expanded.svg @@ -0,0 +1,520 @@ + +image/svg+xml0 +1 +2 +3 +4 +5 + \ No newline at end of file diff --git a/04-08-amidakuji/small-expanded.svg.png b/04-08-amidakuji/small-expanded.svg.png new file mode 100644 index 0000000..b720b61 Binary files /dev/null and b/04-08-amidakuji/small-expanded.svg.png differ diff --git a/04-08-amidakuji/small-packed.svg b/04-08-amidakuji/small-packed.svg new file mode 100644 index 0000000..b5c3808 --- /dev/null +++ b/04-08-amidakuji/small-packed.svg @@ -0,0 +1,522 @@ + +image/svg+xml0 +1 +2 +3 +4 +5 + \ No newline at end of file diff --git a/04-08-amidakuji/small-packed.svg.png b/04-08-amidakuji/small-packed.svg.png new file mode 100644 index 0000000..eff606c Binary files /dev/null and b/04-08-amidakuji/small-packed.svg.png differ diff --git a/04-08-amidakuji/small-unpaired.svg b/04-08-amidakuji/small-unpaired.svg new file mode 100644 index 0000000..2dfe663 --- /dev/null +++ b/04-08-amidakuji/small-unpaired.svg @@ -0,0 +1,405 @@ + +image/svg+xml0 +1 +2 +3 +4 +5 + \ No newline at end of file diff --git a/04-08-amidakuji/small-untriple-1.svg b/04-08-amidakuji/small-untriple-1.svg new file mode 100644 index 0000000..e7554c3 --- /dev/null +++ b/04-08-amidakuji/small-untriple-1.svg @@ -0,0 +1,405 @@ + +image/svg+xml0 +1 +2 +3 +4 +5 + \ No newline at end of file diff --git a/04-08-amidakuji/small-untriple-2.svg b/04-08-amidakuji/small-untriple-2.svg new file mode 100644 index 0000000..97413e4 --- /dev/null +++ b/04-08-amidakuji/small-untriple-2.svg @@ -0,0 +1,373 @@ + +image/svg+xml0 +1 +2 +3 +4 +5 + \ No newline at end of file diff --git a/04-08-amidakuji/untriple-general.svg b/04-08-amidakuji/untriple-general.svg new file mode 100644 index 0000000..c560e76 --- /dev/null +++ b/04-08-amidakuji/untriple-general.svg @@ -0,0 +1,310 @@ + +image/svg+xml \ No newline at end of file