Created sample tours and images of them
[ou-summer-of-code-2017.git] / 00-holiday-specs / holiday-specs-solution.ipynb
index c814a6ec0da0c85419bff650823514d5c8508de7..b54dd5f6fc6f57740377926692ce319b6137dea4 100644 (file)
@@ -44,7 +44,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 52,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [
     {
@@ -58,7 +58,7 @@
        " ['01578ed4e77', '1170', 'Geoje-Si', '487']]"
       ]
      },
-     "execution_count": 52,
+     "execution_count": 1,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -83,7 +83,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 53,
+   "execution_count": 2,
    "metadata": {},
    "outputs": [
     {
@@ -94,7 +94,7 @@
        " ['a6538cfa970', '1100', 'Parowan', '661']]"
       ]
      },
-     "execution_count": 53,
+     "execution_count": 2,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 54,
+   "execution_count": 38,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[['d77b1148', '1396', 'Mamula', '579'],\n",
+       " ['42e05169e', '1104', 'Jayuya', '476'],\n",
+       " ['a6538cfa970', '1100', 'Parowan', '661']]"
+      ]
+     },
+     "execution_count": 38,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "holidays = [h.split() for h in open('00-prices.txt').readlines()]\n",
+    "holidays[:3]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
    "metadata": {},
    "outputs": [
     {
        "9"
       ]
      },
-     "execution_count": 54,
+     "execution_count": 3,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 55,
+   "execution_count": 4,
    "metadata": {},
    "outputs": [
     {
        "124"
       ]
      },
-     "execution_count": 55,
+     "execution_count": 4,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 56,
+   "execution_count": 5,
    "metadata": {},
    "outputs": [
     {
        "9"
       ]
      },
-     "execution_count": 56,
+     "execution_count": 5,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 104,
+   "execution_count": 6,
    "metadata": {},
    "outputs": [
     {
        "9"
       ]
      },
-     "execution_count": 104,
+     "execution_count": 6,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 95,
+   "execution_count": 7,
    "metadata": {},
    "outputs": [
     {
        "9"
       ]
      },
-     "execution_count": 95,
+     "execution_count": 7,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 96,
+   "execution_count": 8,
    "metadata": {},
    "outputs": [
     {
        "1"
       ]
      },
-     "execution_count": 96,
+     "execution_count": 8,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 58,
+   "execution_count": 9,
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 85,
+   "execution_count": 10,
    "metadata": {
     "collapsed": true
    },
   },
   {
    "cell_type": "code",
-   "execution_count": 59,
+   "execution_count": 11,
    "metadata": {},
    "outputs": [
     {
        "'627824317b47'"
       ]
      },
-     "execution_count": 59,
+     "execution_count": 11,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 60,
+   "execution_count": 12,
    "metadata": {},
    "outputs": [
     {
        "['627824317b47', '909', 'Giessenmestia', '532']"
       ]
      },
-     "execution_count": 60,
+     "execution_count": 12,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 86,
+   "execution_count": 13,
    "metadata": {},
    "outputs": [
     {
        "['627824317b47', '909', 'Giessenmestia', '532']"
       ]
      },
-     "execution_count": 86,
+     "execution_count": 13,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 90,
+   "execution_count": 14,
    "metadata": {},
    "outputs": [
     {
        "'627824317b47'"
       ]
      },
-     "execution_count": 90,
+     "execution_count": 14,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 98,
+   "execution_count": 15,
    "metadata": {},
    "outputs": [
     {
        "'627824317b47'"
       ]
      },
-     "execution_count": 98,
+     "execution_count": 15,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 94,
+   "execution_count": 16,
    "metadata": {},
    "outputs": [
     {
        "'627824317b47'"
       ]
      },
-     "execution_count": 94,
+     "execution_count": 16,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 97,
+   "execution_count": 17,
    "metadata": {},
    "outputs": [
     {
        "'627824317b47'"
       ]
      },
-     "execution_count": 97,
+     "execution_count": 17,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 61,
+   "execution_count": 18,
    "metadata": {},
    "outputs": [
     {
        " ['d4ab30071b', '895', 'Nullarbor', '589']]"
       ]
      },
-     "execution_count": 61,
+     "execution_count": 18,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 87,
+   "execution_count": 19,
    "metadata": {},
    "outputs": [
     {
        " ['d4ab30071b', '895', 'Nullarbor', '589']]"
       ]
      },
-     "execution_count": 87,
+     "execution_count": 19,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 62,
+   "execution_count": 20,
    "metadata": {},
    "outputs": [
     {
        "['cf8876d4e73', '823', 'Stonington-Island', '693']"
       ]
      },
-     "execution_count": 62,
+     "execution_count": 20,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 63,
+   "execution_count": 21,
    "metadata": {},
    "outputs": [
     {
        " ['d4ab30071b', '895', 'Nullarbor', '589']]"
       ]
      },
-     "execution_count": 63,
+     "execution_count": 21,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 64,
+   "execution_count": 22,
    "metadata": {},
    "outputs": [
     {
        "['a68d97fbfdb', '987', 'Brorfelde', '451']"
       ]
      },
-     "execution_count": 64,
+     "execution_count": 22,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 65,
+   "execution_count": 23,
    "metadata": {},
    "outputs": [
     {
        " ['be8b9d110', '984', 'Tubakuba', '485']]"
       ]
      },
-     "execution_count": 65,
+     "execution_count": 23,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 66,
+   "execution_count": 24,
    "metadata": {},
    "outputs": [
     {
        " ['f22c113c', '1217', 'Mamula', '521']]"
       ]
      },
-     "execution_count": 66,
+     "execution_count": 24,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 67,
+   "execution_count": 25,
    "metadata": {},
    "outputs": [
     {
        "2130"
       ]
      },
-     "execution_count": 67,
+     "execution_count": 25,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 68,
+   "execution_count": 26,
    "metadata": {},
    "outputs": [
     {
        "2158"
       ]
      },
-     "execution_count": 68,
+     "execution_count": 26,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 69,
+   "execution_count": 27,
    "metadata": {},
    "outputs": [
     {
        "2101"
       ]
      },
-     "execution_count": 69,
+     "execution_count": 27,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "collapsed": true
-   },
-   "outputs": [],
-   "source": []
+   "execution_count": 39,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "'627824317b47'"
+      ]
+     },
+     "execution_count": 39,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "hs = iter(holidays)\n",
+    "first_holiday = next(hs)\n",
+    "best_value = cost_of_holiday(first_holiday)\n",
+    "best_holiday = first_holiday[0]\n",
+    "\n",
+    "for h in hs:\n",
+    "    if cost_of_holiday(h) < best_value:\n",
+    "        best_value = cost_of_holiday(h)\n",
+    "        best_holiday = h[0]\n",
+    "\n",
+    "best_holiday"
+   ]
   },
   {
    "cell_type": "code",
-   "execution_count": 70,
+   "execution_count": 28,
    "metadata": {},
    "outputs": [
     {
        "1441"
       ]
      },
-     "execution_count": 70,
+     "execution_count": 28,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 71,
+   "execution_count": 29,
    "metadata": {},
    "outputs": [
     {
        "1446"
       ]
      },
-     "execution_count": 71,
+     "execution_count": 29,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 72,
+   "execution_count": 30,
    "metadata": {},
    "outputs": [
     {
        " ['be8b9d110', '984', 'Tubakuba', '485']]"
       ]
      },
-     "execution_count": 72,
+     "execution_count": 30,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 73,
+   "execution_count": 31,
    "metadata": {},
    "outputs": [
     {
        " ['52c6f5bab4', '1305', 'Nullarbor', '605']]"
       ]
      },
-     "execution_count": 73,
+     "execution_count": 31,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 74,
+   "execution_count": 32,
    "metadata": {},
    "outputs": [
     {
        " (['01578ed4e77', '1170', 'Geoje-Si', '487'], 1170)]"
       ]
      },
-     "execution_count": 74,
+     "execution_count": 32,
      "metadata": {},
      "output_type": "execute_result"
     }
   },
   {
    "cell_type": "code",
-   "execution_count": 75,
+   "execution_count": 33,
    "metadata": {},
    "outputs": [
     {