Added worked example text
authorNeil Smith <neil.git@njae.me.uk>
Sun, 6 Aug 2017 14:46:37 +0000 (15:46 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Sun, 6 Aug 2017 14:46:37 +0000 (15:46 +0100)
06-tour-shapes/tour-shapes-solution.ipynb

index c4949e8a5dcd3027e8325586021931d37ba7775a..e5efe3d14fd4332b0441c77ad25224469dc542a9 100644 (file)
     "The tours are still given in [06-tours.txt](06-tours.txt), one tour per line. Your definition of a valid tour now includes the combination of two partial tours, so long as the combined tour never crosses itself and returns you to your staring place. With this new definition of valid tours, what is the total length of all the valid tours?"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "# Worked solution: part 1\n",
+    "This is a case where I'd like to have a stronger type system than what Python provides. During my development on this problem, I had several cases where bugs would have been caught by a type-checking compiler. (Python does have [type checking](https://docs.python.org/3/library/typing.html) since Python 3.5, but I've never used it!)\n",
+    "\n",
+    "Validity checking is about finding the places you've been on the tour. But, while tracing the tour, it's not enough just to keep track of the current position: you also need to keep track of the current direction, so you know which direction to step next.\n",
+    "\n",
+    "This led me to having three different ways of representing a tour, which is why I wanted three different types.\n",
+    "\n",
+    "* A **tour** is the string that's the input: a sequence of `FLRFF`-type letters.\n",
+    "* A **trace** is a sequence of position/direction thingies, which you use to find out where the tour takes you.\n",
+    "* The **positions** are just the positions you get to, regardless of direction you happen to be.\n",
+    "\n",
+    "If we can find the **positions** of a **tour**, we can easily say if that **tour** is valid: it's valid if and only if:\n",
+    "1. The first position == the last position == (0, 0)\n",
+    "2. The length of the set of positions is one more than the length of the sequence of positions\n",
+    "\n",
+    "(Converting from a `list` to a `set` removes duplicates. If we only remove one duplicate, the end points, that means all the other positions are unique.)\n",
+    "\n",
+    "So, we can determine validity from **positions**, **positions** from a **trace**, and a **trace** from a tour. All we need to do now is build those transformations!\n",
+    "\n",
+    "A **tour** is just a string of characters. \n",
+    "\n",
+    "A **trace** is a list of **Step**s, and each step has an `x` and `y` position and a `direction`. The position is where that step starts. There's always one more **Step** in a **trace** than the length of the **tour**, as the **trace** is the end points of the steps and the **tour** is the steps themselves. (This is an example of a [fencepost correction](https://en.wikipedia.org/wiki/Off-by-one_error#Fencepost_error).)\n",
+    "\n",
+    "Writing this out explicitly for the first time makes me realise I got the name of `Step` very wrong!\n",
+    "\n",
+    "## Transformation 1: tour to trace\n",
+    "The first thing to fix is the direction. I could use numbers for the direction, but in this case I decided to use Python's `Enum` type to make the code more readable and prevent typos. Then I defined a couple of functions, `turn_left()` and `turn_right()`, to return the new direction after a left and right turn. \n",
+    "\n",
+    "With directions sorted, `advance()` takes a step a position and a direction, and moves to the new point in that direction. `step()` takes a tour instruction and a current `Step` and returns the new `Step`. `trace_tour()` takes a **tour** (and an optional starting position) and applies `step()` character by character to build a complete **trace**.\n",
+    "\n",
+    "(For those interested in higher order functions, you can't use a `map` to calculate a **trace**, as you can't treat each character in the **tour** independently. You could do it with `functools.reduce`, which is a left fold, building up the complete **trace** as the accumulated value. But I'll leave that as an exercise for the reader.)\n",
+    "\n",
+    "## Transformation 2: trace to positions\n",
+    "This is much simpler. Given a sequence of `Step`s, just pull out the `x` and `y` positions. I keep the position as a 2-tuple of `(x, y)`. It's done as a list comprehension, effectively a `map`.\n",
+    "\n",
+    "## Transformation 3: trace to validity\n",
+    "For no good reason, I decided to make the `valid()` predicate act on **trace**s, not **positions**. Still, it uses the **trace** to **positions** transformation internally.\n",
+    "\n",
+    "## Solving part 1\n",
+    "With the transformations above, it's easy to solve part 1. We read the list of **tour**s from the file, and use the comprehension to filter only the valid **tour**s (the `if valid(trace_tour(t))` part), converting the **tour** to its length, and using `sum` to add them all up."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## Worked solution: part 2\n",
+    "Essentially, we take every **tour** and combine it with every other **tour** and, if the resulting combination is valid, add its length to the total. The problem is, the validity check is quite expensive and blindly testing every combination of **tour**s takes 1m 30s, which is a bit too long.\n",
+    "\n",
+    "The interesting part of this question is to reduce the number of possible combinations we check. \n",
+    "\n",
+    "* If a tour is valid by itself, we don't want to combine it with any other tours.\n",
+    "* If a tour loops back on itself, any combination it forms won't be valid, so we don't need to check it\n",
+    "* For two tours to form a valid combination, the overall displacement of the two tours (the distance from the origin to the end of the partial tour) has to be about the same.\n",
+    "\n",
+    "The first and third optimisations are the most powerful, dropping the total runtime down from 1½ minutes to under a second. The second optimisation brings the runtime down to about half a second. \n",
+    "\n",
+    "We can do the \"tour displacement\" optimisation by finding the **trace** of each **tour** then finding the distance from the start of the tour to the end. There are lots of distance metrics I could use, including the common Euclidean distance (found with Pythagoras's theorem), also known as the $L_2$ norm. But the maths is a be easier if I use the taxicab distance, also known as the $L_1$ norm. \n",
+    "\n",
+    "I use a `dict` called `l1s` to store this information. The key is the l1 norm, and the value is a list of **tour**s with that l1 norm. We can then go through the `l1s` dict, norm value by norm value, and pull out the tours that have a close displacement and therefore are worth checking whether the combination is valid. The combination is formed from `t1` (with this displacement) and `t2` (with a close displacement). If the combination is valid, it's added to the `goods` list. \n",
+    "\n",
+    "Careful dataset creation means that if `t1+t2` is valid, `t2+t1` isn't! If it were, there would be questions about whether `t1+t2` is a different tour from `t2+t1`, and it's easier to just not deal with that particular case in this problem.\n",
+    "\n",
+    "The second optimisation restricts the **tour**s that go into `l1s` by not including **tour**s that have loops. That's done with a new version of `valid()` called `valid_part()`"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## An aside on norms\n",
+    "> \"[Norm](https://en.wikipedia.org/wiki/Norm_%28mathematics%29)\" is the fancy maths name for \"distance\" (roughly). There are lots of ways of calculating it. The $L_2$ norm is the standard one we know and love:\n",
+    "\n",
+    "> * $L_2 = \\sqrt{|x|^2 + |y|^2}$\n",
+    "\n",
+    "> (where $|x|$ means the absolute value of $x$, ignoring sign; this is often implemented as `abs(x)`.)\n",
+    "\n",
+    "> We can apply norms to higher dimensional spaces by just putting more co-ordinate components in the root, like $L_2 = \\sqrt{\\dots + |w|^2 + |x|^2 + |y|^2 + |z|^2 + \\dots}$\n",
+    "\n",
+    "> Other norms use differnet powers, so we have:\n",
+    "\n",
+    "> * $L_3 = \\sqrt[3]{|x|^3 + |y|^3}$\n",
+    "> * $L_4 = \\sqrt[4]{|x|^4 + |y|^4}$\n",
+    "> * $L_p = \\sqrt[p]{|x|^p + |y|^p}$\n",
+    "\n",
+    "> Basically, as the norm number in increases, the norm puts more emphasis on the largest co-ordinate difference. There are a few special cases you may come across.\n",
+    "\n",
+    "> * $L_1 = \\sqrt[1]{|x|^1 + |y|^1} = |x| + |y|$, which is the distance if you can only move horizontally or vertically, not diagonally. It's also known as the Manhattan distance or taxicab distance, after US city layouts.\n",
+    "\n",
+    "> * $L_0 = \\sqrt[0]{|x|^0 + |y|^0}$, but as $0^0 = 0$ and $(\\mathrm{anything\\ else})^0 = 1$, this counts the number of coordinates that are non-zero. It's also known as the Hamming distance.\n",
+    "\n",
+    "> * $L_\\infty = \\sqrt[\\infty]{|x|^\\infty + |y|^\\infty}$, isn't meaningful in itself, but makes sense as the limiting case as $p \\to \\infty$ and is $max(|x|, |y|)$."
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": 1,
   },
   {
    "cell_type": "code",
-   "execution_count": 39,
+   "execution_count": 16,
    "metadata": {
     "collapsed": true
    },
      "data": {
       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUQAAAEACAYAAADLIw+8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAF05JREFUeJzt3XuQVeWd7vHv0xCgLwNRQUZgbI8mOdFJTlQsbGMue6JG\nyBiZWCbGk6pcjsRkalKmynjKSyxotKx4C14mkxAN5oBVKVHjBRwimNJ9FJ2ghRglwMjERERAcwQh\nfZO+/M4f/drV6eyGbvbqXt3b51O1i3V593p/u7p5+l1rr71fRQRmZgZVeRdgZjZSOBDNzBIHoplZ\n4kA0M0sciGZmiQPRzCwpOxAljZe0TtIGSS9JWlCizThJ90jaKuk/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MlYjYJ6kIzGYA19tGidOBcyV9DqgG/kbSsoj4aqnGI/2UuVKu\nI/bcnC5pHN03px/w3a5R6KB/fUexu4BNEXFb3oVkTdJkSZPScjVwJrAl36qyExFXRcTREXEs3f/v\nHu8vDGEEBmJ/N3uPZpV+c7qkXwDPAB+StE3SN/KuKSuSTge+Anwm3ZryvKTZedeVoaOAJyS9QPe1\n0dURsSrnmnLjG7PNzJIRN0I0M8uLA9HMLHEgmpklDkQzs8SBaGaWOBDNzBIHoplZ4kA0M0v+P7R8\nnO0IPfrWAAAAAElFTkSuQmCC\n",
       "text/plain": [
-       "<matplotlib.figure.Figure at 0x7f365877fd30>"
+       "<matplotlib.figure.Figure at 0x7fc9c2dffcc0>"
       ]
      },
      "metadata": {},
   },
   {
    "cell_type": "code",
-   "execution_count": 37,
+   "execution_count": 18,
    "metadata": {},
    "outputs": [
     {
      "data": {
       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAN4AAAEACAYAAADcJMhcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE9ZJREFUeJzt3X1wlfWZxvHvffJOEqRCLYoL2qGuLzgo7QBVnIk7Rqho\nRZe26661gwwdba2lMy5qkSZIGSmtQ3EtO9VRtEwVLeIWsVLAbtaXSnVWqMmKIFOLKCijVTQkkJdz\n7x+BNEBITjgn5z4h12fmGc9Jfud5rmCu/J7nOYGfuTsikl2J6AAi/ZGKJxJAxRMJoOKJBFDxRAKo\neCIB0i6emZ1qZn8ws9fNrNbMbs5EMJHjmaX7Pp6ZDQWGuvsmMysD/he40t3fyERAkeNR2jOeu7/n\n7psOPK4HNgPD0t2vyPEso9d4ZnYacB7wp0zuV+R4k7HiHTjNXAF8/8DMJyJHkZ+JnZhZPm2lW+bu\nvz3KGP1SqPQL7m7djcnUjPcg8Lq7L+4mUE5tVVVV4Rn6QqZczZWLmVKVibcTLgT+DfgnM9toZq+a\n2aR09ytyPEv7VNPdXwTyMpBFpN/o17+5UlFRER3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ure at 0x7fc9c2dc5cf8>"
       ]
      },
      "metadata": {},
   },
   {
    "cell_type": "code",
-   "execution_count": 38,
+   "execution_count": 19,
    "metadata": {},
    "outputs": [
     {
      "data": {
       "image/png": "iVBORw0KGgoAAAANSUhEUgAAASMAAAEACAYAAAD4GBC1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAF09JREFUeJzt3Xt0lfWd7/H3d+eyE66pKKBSSq2OOKNUqYuCTns27XQE\nFZiWqR1mTk+9VFyWHkRQlF4MtHAEl4wtpfUPxrKWPSLL6upoVQJ20Q0yFktRCgVRVASngBqWQkIu\nhOR7/sgmK3qAJO4nz/Mj+/NaKyt7J7/8Pr/cPvnt/TzwmLsjIpK0VNILEBEBlZGIBEJlJCJBUBmJ\nSBBURiISBJWRiAShOIpJzOwt4BDQAjS5+6go5hWRwhFJGdFaQhl3fz+i+USkwET1MM0inEtEClBU\nBeLAajPbZGY3RzSniBSQqB6mXeHuB8zsLOA5M3vF3TdENLeIFIBIysjdD+Rev2dmvwFGAR8qIzPT\nP4ITKVDubh2Nyfthmpn1MrM+udu9gX8E/nKSBSX2UllZqfwCzFZ+8vmdFcXOaBDwm9zOpxh4xN3X\nRDCviBSQvMvI3XcDl0awFhEpYAVzOD6TySi/ALOVn3x+Z1lXHtPlFWTmcWWJSDjMDI/jCWwRkSio\njEQkCCojEQmCykhEgqAyEpEgqIxEJAgqIxEJgspIRIKgMhKRIKiMRCQIKiMRCYLKSESCoDISkSCo\njEQkCCojEQmCykhEgqAyEpEgqIxEJAgqIxEJgspIRIKgMhKRIERWRmaWMrOXzOypqOYUkcIR5c7o\nNmBHhPOJSAGJpIzMbAhwNfAfUczXU9XW1rJ06VL279+f9FJEgpP35a1zHgDuBPpHNF+PUlNTw5Il\nS1i0aBH19fW0tLQwderU2PKLioooKSmJLU/k48j7irJmdg0w3t2/a2YZYJa7TzjBOK+srGy7n8lk\nTpvL7ubrrLPOorq6Gmi7umbsa9i8eTMjR46MPVcKTzabJZvNtt2fN29ep64oi7vn9QL8H2Av8Caw\nH6gFHj7BOC9UgE+cONErKiq8qKjIf/GLX8SWvWDBAk+lUj5u3LjYMkXay/3ud9glee+M2jOz/0Hr\nzmjiCd7nUWadTsyMxYsXc+utt7JixQomTJjAwIEDuz23traWc845h5qaGsrLy9m4cSMjRozo9lyR\n9nKPBjrcGek8oxiVl5dz0003xVJEAOvWrePIkSMANDY2smLFilhyRT6OqJ7ABsDd1wHropxTPr7x\n48ezZcsWRowYwS9/+UsmT56c9JJETko7ox4slUpxySWXADB8+HD69OmT8IpETk5lJCJBUBmJSBBU\nRiISBJWRiARBZSQiQVAZiUgQVEYiEgSVkYgEQWUkIkFQGYlIEFRGIhIElZGIBEFlJCJBUBmJSBBU\nRiISBJWRiARBZSQiQVAZiUgQVEYiEgSVkYgEQWUkIkFQGYlIEPIuIzNLm9mLZvaymW0zs8ooFtYT\ntLS08NRTTwGwfv163nzzzYRXJBKuvC/i6O6NZjbW3evMrAj4LzNb5e5/jGB9p7Vt27YxadIkAJ5+\n+mlKS0t57LHHEl6VSJgieZjm7nW5m2laC86jmDdq1dXVzJkzhz/+MZ6eHDFiBBdffDEA6XSamTNn\nxpIrcjqK5PLWZpYCNgOfAX7u7puimDcqBw4c4P777+fBBx+koaGBLVu2cOedd8aS/c1vfpO7776b\nkSNHMnr06FgyRU5HkZSRu7cAl5lZP+A/zexv3X3HR8fNnTu37XYmkyGTyUQR36GRI0eyf//+tvtV\nVVVUVVXFkn3cggULYs077uDBg5SXl/Pee+8lki+FJ5vNks1mu/xx5h7tIyozuweodfd//8jbPeqs\nLqyJL3zhCxw+fJitW7dy5513smjRokTWErfZs2ezePFiRo0axR/+8IeklyMFyMxwd+toXBRH0840\ns/652+XAPwA78503agMHDuTll18mm81y1113Jb2cWBw8eJCf//zntLS0sHXrVjZs2JD0kkROKoon\nsM8Gfm9mW4AXgdXu/mwE80bOzPjiF7/IGWeckfRSYrF582bq6+sBqKurY82aNQmvSOTko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7+dQjhJ81zg7Xb3\n/5uYfxlDYWbDaN2lvRhzbsrMXgYOAM+5+6YY4x8A7iTGAjwBB1ab2SYzu/lUAyMvIzN7zsy2tnvZ\nlns9AcDdf+DuQ4FHaH2oFmt+bky3nKTZmeyYnWgXVnBHLMysD/A4cNtHdufdzt1b3P0yWnfhnzez\nv40j18yuAd7J7QyNeHfk7V3h7pfTukObZmZ/f7KBeZ1ndCLu/pVODn0UeAaYG2d+7iTNq4EvRZnb\nmewE/DcwtN39IcC+hNaSCDMrprWIfuXuTya1Dnc/bGZZYBywI4bIK4GJZnY1UA70NbOH3f1/xZDd\nxt0P5F6/Z2a/ofWpgw0nGhv30bTz292dROtj+Djzj5+kOdE7OEmzu5cSU84m4Hwz+5SZlQL/AsR9\nVCXJv8oAvwR2uPtP4w42szPNrH/udjmtB1B2xpHt7t9z96Hufh6t3/e1cReRmfXK7Uoxs97APwJ/\nOdn4uJ8zWph72LKF1m/MbTHn/4zWoyrP5Q53/iKuYDP7JzN7GxgNPG1m3f58lbs3A9+l9b962Q6s\ndPfY/gCY2QrgBeBvzGyvmd0QV3Yu/0rg34Av5Q4tv5T7gxSXs4Hf537eXwRWu/uzMeYnbRCwIfec\n2Ubgt+6+5mSDddKjiARB/+2siARBZSQiQVAZiUgQVEYiEgSVkYgEQWUkIkFQGYlIEFRGIhKE/wdL\nGE/mZ+od3gAAAABJRU5ErkJggg==\n",
       "text/plain": [
-       "<matplotlib.figure.Figure at 0x7f3658758860>"
+       "<matplotlib.figure.Figure at 0x7fc9c2ceb748>"
       ]
      },
      "metadata": {},
   },
   {
    "cell_type": "code",
-   "execution_count": 18,
+   "execution_count": 20,
    "metadata": {},
    "outputs": [
     {
        "226"
       ]
      },
-     "execution_count": 18,
+     "execution_count": 20,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 19,
+   "execution_count": 21,
    "metadata": {},
    "outputs": [
     {
        "61762"
       ]
      },
-     "execution_count": 19,
+     "execution_count": 21,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 20,
+   "execution_count": 22,
    "metadata": {},
    "outputs": [
     {
        "100"
       ]
      },
-     "execution_count": 20,
+     "execution_count": 22,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 21,
+   "execution_count": 23,
    "metadata": {},
    "outputs": [
     {
        "123845"
       ]
      },
-     "execution_count": 21,
+     "execution_count": 23,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 22,
+   "execution_count": 24,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "10 loops, best of 3: 196 ms per loop\n"
+      "10 loops, best of 3: 192 ms per loop\n"
      ]
     }
    ],
   },
   {
    "cell_type": "code",
-   "execution_count": 23,
+   "execution_count": 25,
    "metadata": {},
    "outputs": [
     {
        "80622"
       ]
      },
-     "execution_count": 23,
+     "execution_count": 25,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 24,
+   "execution_count": 26,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "1 loop, best of 3: 1min 32s per loop\n"
+      "1 loop, best of 3: 1min 30s per loop\n"
      ]
     }
    ],
   },
   {
    "cell_type": "code",
-   "execution_count": 25,
+   "execution_count": 27,
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 26,
+   "execution_count": 28,
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 27,
+   "execution_count": 57,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def valid_part(trace):\n",
+    "    return ((trace[-1].x != 0 \n",
+    "             or trace[-1].y != 0)\n",
+    "            and len(set(positions(trace))) == len(trace))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 62,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "5 1\n",
+      "6 1\n",
+      "8 1\n",
+      "11 1\n",
+      "19 1\n"
+     ]
+    }
+   ],
+   "source": [
+    "l1s = {}\n",
+    "for t in tours:\n",
+    "    tr = trace_tour(t)\n",
+    "    if valid_part(tr):\n",
+    "        l1 = abs(tr[-1].x) + abs(tr[-1].y)\n",
+    "        if l1 not in l1s:\n",
+    "            l1s[l1] = []\n",
+    "        l1s[l1] += [t]\n",
+    "\n",
+    "for l1 in l1s:\n",
+    "    if l1 < 20:\n",
+    "        print(l1, len(l1s[l1]))   "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 59,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "13"
+      ]
+     },
+     "execution_count": 59,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "good_is = []\n",
+    "goods = []\n",
+    "for l1 in l1s:\n",
+    "    possible_l1s = [i for i in range(l1-1, l1+1) if i in l1s]\n",
+    "    candidates = [t for i in possible_l1s for t in l1s[i]]\n",
+    "    for t1 in l1s[l1]:\n",
+    "        for t2 in candidates:\n",
+    "            if t1 != t2:\n",
+    "                t12 = t1 + t2                \n",
+    "                if valid(trace_tour(t12)):\n",
+    "                    good_is += [(tours.index(t1), tours.index(t2))]\n",
+    "                    goods += [t12] \n",
+    "len(goods)            "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 60,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "80622"
+      ]
+     },
+     "execution_count": 60,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "(sum(len(t) for t in tours if valid(trace_tour(t)))\n",
+    "    +\n",
+    "    sum(len(t12) for t12 in goods)\n",
+    ")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 64,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "1 loop, best of 3: 517 ms per loop\n"
+     ]
+    }
+   ],
+   "source": [
+    "%%timeit\n",
+    "\n",
+    "l1s = {}\n",
+    "for t in tours:\n",
+    "    tr = trace_tour(t)\n",
+    "    if valid_part(tr):\n",
+    "        l1 = abs(tr[-1].x) + abs(tr[-1].y)\n",
+    "        if l1 > 0:\n",
+    "            if l1 not in l1s:\n",
+    "                l1s[l1] = []\n",
+    "            l1s[l1] += [t]\n",
+    "\n",
+    "good_is = []\n",
+    "goods = []\n",
+    "for l1 in l1s:\n",
+    "    possible_l1s = [i for i in range(l1-1, l1+1) if i in l1s]\n",
+    "    candidates = [t for i in possible_l1s for t in l1s[i]]\n",
+    "    for t1 in l1s[l1]:\n",
+    "        for t2 in candidates:\n",
+    "            if t1 != t2:\n",
+    "                t12 = t1 + t2                \n",
+    "                if valid(trace_tour(t12)):\n",
+    "                    good_is += [(tours.index(t1), tours.index(t2))]\n",
+    "                    goods += [t12] \n",
+    "        \n",
+    "(sum(len(t) for t in tours if valid(trace_tour(t)))\n",
+    "    +\n",
+    "    sum(len(t12) for t12 in goods)\n",
+    ")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 67,
    "metadata": {},
    "outputs": [
     {
   },
   {
    "cell_type": "code",
-   "execution_count": 28,
+   "execution_count": 66,
    "metadata": {},
    "outputs": [
     {
        " (19, 1)]"
       ]
      },
-     "execution_count": 28,
+     "execution_count": 66,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 29,
+   "execution_count": 31,
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 30,
-   "metadata": {
-    "collapsed": true
-   },
-   "outputs": [],
+   "execution_count": 63,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "13"
+      ]
+     },
+     "execution_count": 63,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
    "source": [
     "good_is = []\n",
     "goods = []\n",
-    "tried = []\n",
     "for l1 in l1s:\n",
     "    possible_l1s = [i for i in range(l1-1, l1+1) if i in l1s]\n",
     "    candidates = [t for i in possible_l1s for t in l1s[i]]\n",
-    "    for t1 in candidates:\n",
+    "    for t1 in l1s[l1]:\n",
     "        for t2 in candidates:\n",
     "            if t1 != t2:\n",
-    "                t12 = t1 + t2\n",
-    "                if (t12) not in tried:\n",
-    "                    tried += [(t12)]\n",
-    "                    if valid(trace_tour(t12)):\n",
-    "                        good_is += [(tours.index(t1), tours.index(t2))]\n",
-    "                        goods += [t12]"
+    "                t12 = t1 + t2                \n",
+    "                if valid(trace_tour(t12)):\n",
+    "                    good_is += [(tours.index(t1), tours.index(t2))]\n",
+    "                    goods += [t12]\n",
+    "len(goods)"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 31,
+   "execution_count": 42,
    "metadata": {},
    "outputs": [
     {
        "80622"
       ]
      },
-     "execution_count": 31,
+     "execution_count": 42,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 32,
+   "execution_count": 50,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "1 loop, best of 3: 1.2 s per loop\n"
+      "1 loop, best of 3: 998 ms per loop\n"
      ]
     }
    ],
     "            l1s[l1] = []\n",
     "        l1s[l1] += [t]\n",
     "\n",
+    "good_is = []\n",
     "goods = []\n",
-    "tried = []\n",
     "for l1 in l1s:\n",
     "    possible_l1s = [i for i in range(l1-1, l1+1) if i in l1s]\n",
     "    candidates = [t for i in possible_l1s for t in l1s[i]]\n",
-    "    for t1 in candidates:\n",
+    "    for t1 in l1s[l1]:\n",
     "        for t2 in candidates:\n",
     "            if t1 != t2:\n",
-    "                t12 = t1 + t2\n",
-    "                if (t12) not in tried:\n",
-    "                    tried += [(t12)]\n",
-    "                    if valid(trace_tour(t12)):\n",
-    "                        goods += [t12]\n",
-    "\n",
+    "                t12 = t1 + t2                \n",
+    "                if valid(trace_tour(t12)):\n",
+    "                    good_is += [(tours.index(t1), tours.index(t2))]\n",
+    "                    goods += [t12] \n",
+    "        \n",
     "(sum(len(t) for t in tours if valid(trace_tour(t)))\n",
     "    +\n",
     "    sum(len(t12) for t12 in goods)\n",
   },
   {
    "cell_type": "code",
-   "execution_count": 33,
+   "execution_count": 47,
    "metadata": {},
    "outputs": [
     {
        "13"
       ]
      },
-     "execution_count": 33,
+     "execution_count": 47,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 34,
+   "execution_count": 56,
    "metadata": {},
    "outputs": [
     {
        " (212, 113)]"
       ]
      },
-     "execution_count": 34,
+     "execution_count": 56,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 35,
+   "execution_count": 55,
    "metadata": {},
    "outputs": [
     {
        " (208, 204)]"
       ]
      },
-     "execution_count": 35,
+     "execution_count": 55,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 36,
-   "metadata": {},
+   "execution_count": 54,
+   "metadata": {
+    "scrolled": true
+   },
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "[(1, 1),\n",
-       " (2, 1),\n",
-       " (3, 4),\n",
-       " (4, 5),\n",
-       " (5, 7),\n",
-       " (6, 3),\n",
-       " (7, 1),\n",
-       " (8, 2),\n",
-       " (9, 2),\n",
-       " (11, 2),\n",
-       " (18, 1),\n",
+       "[(66, 2),\n",
+       " (68, 1),\n",
+       " (5, 1),\n",
+       " (6, 1),\n",
+       " (8, 1),\n",
+       " (74, 1),\n",
+       " (11, 1),\n",
+       " (76, 2),\n",
+       " (34, 2),\n",
+       " (81, 1),\n",
        " (19, 1),\n",
        " (21, 1),\n",
-       " (24, 1),\n",
+       " (88, 1),\n",
        " (132, 2),\n",
        " (26, 2),\n",
        " (28, 1),\n",
-       " (29, 1),\n",
-       " (34, 2),\n",
+       " (94, 1),\n",
+       " (37, 2),\n",
+       " (98, 1),\n",
        " (36, 1),\n",
-       " (37, 3),\n",
+       " (101, 2),\n",
        " (166, 2),\n",
        " (40, 2),\n",
        " (41, 2),\n",
-       " (44, 3),\n",
-       " (46, 1),\n",
-       " (48, 2),\n",
-       " (50, 3),\n",
-       " (52, 2),\n",
-       " (53, 1),\n",
-       " (54, 1),\n",
+       " (106, 1),\n",
+       " (107, 1),\n",
+       " (44, 2),\n",
+       " (48, 1),\n",
+       " (114, 2),\n",
+       " (117, 2),\n",
        " (56, 2),\n",
        " (57, 3),\n",
        " (58, 1),\n",
        " (59, 2),\n",
-       " (61, 1),\n",
-       " (64, 1),\n",
-       " (66, 2),\n",
-       " (68, 1),\n",
        " (70, 1),\n",
-       " (74, 1),\n",
-       " (75, 1),\n",
-       " (76, 3),\n",
-       " (77, 1),\n",
-       " (81, 1),\n",
-       " (82, 2),\n",
-       " (86, 1),\n",
-       " (88, 1),\n",
-       " (90, 1),\n",
-       " (94, 1),\n",
-       " (97, 1),\n",
-       " (98, 1),\n",
-       " (101, 2),\n",
-       " (106, 1),\n",
-       " (107, 1),\n",
-       " (114, 2),\n",
-       " (117, 3),\n",
        " (127, 1)]"
       ]
      },
-     "execution_count": 36,
+     "execution_count": 54,
      "metadata": {},
      "output_type": "execute_result"
     }