{ "cells": [ { "cell_type": "code", "execution_count": 329, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import random\n", "import re\n", "import uuid" ] }, { "cell_type": "code", "execution_count": 330, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def cap_after_hyphen(string):\n", " return re.sub(r'\\-(?P[a-z])', \n", " lambda m: '-' + m.group('first').upper(), \n", " string) " ] }, { "cell_type": "code", "execution_count": 331, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Aalborg',\n", " 'Nullarbor',\n", " 'Morgantown',\n", " 'Estacada',\n", " 'Almaty',\n", " 'Tambon-Pa-Fa',\n", " 'Lemnos',\n", " 'Sofia',\n", " 'Puente-Laguna-Garzonkuala-Penyu',\n", " 'Hajnowski',\n", " 'Karlukovo',\n", " 'Mamula',\n", " 'Stonington-Island',\n", " 'Grimsey-Island',\n", " 'Uzupis',\n", " 'Sukhumi',\n", " 'Ijsseloog',\n", " 'Giessenmestia',\n", " 'Nordkapp',\n", " 'Gorongosa',\n", " 'Brorfelde',\n", " 'Parowan',\n", " 'Tubakuba',\n", " 'Geoje-Si',\n", " 'Mora',\n", " 'Holmegaard',\n", " 'Jayuya',\n", " 'Zhangye-Shi',\n", " 'Luoyang']" ] }, "execution_count": 331, "metadata": {}, "output_type": "execute_result" } ], "source": [ "destination_names = ('Aalborg Nullarbor MORGANTOWN ESTACADA ALMATY TAMBON-PA-FA Lemnos Sofia Puente-Laguna-Garzon' +\n", "'KUALA-PENYU HAJNOWSKI KARLUKOVO Mamula STONINGTON-ISLAND Grimsey-Island Uzupis SUKHUMI IJsseloog GIESSEN' +\n", "'MESTIA NORDKAPP GORONGOSA Brorfelde PAROWAN Tubakuba GEOJE-SI MORA HOLMEGAARD JAYUYA ZHANGYE-SHI LUOYANG')\n", "destination_names = destination_names.lower().split()\n", "destination_names = [n[0].upper() + n[1:] for n in destination_names]\n", "destination_names = [cap_after_hyphen(n) for n in destination_names]\n", "\n", "destination_names" ] }, { "cell_type": "code", "execution_count": 332, "metadata": { "collapsed": true }, "outputs": [], "source": [ "few_destination_names = ['Aalborg', 'Nullarbor', 'Morgantown', 'Parowan', 'Tubakuba', 'Geoje-Si']" ] }, { "cell_type": "code", "execution_count": 371, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def make_holiday(name=None):\n", " if not name:\n", " name = random.choice(destination_names)\n", " price = 0\n", " for _ in range(6):\n", " price += random.randint(100, 300)\n", " surcharge = 0\n", " for _ in range(6):\n", " surcharge += random.randint(50, 150)\n", " hol_id = str(uuid.uuid4())[-random.randint(8, 12):]\n", " return hol_id, price, name, surcharge" ] }, { "cell_type": "code", "execution_count": 334, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('db91156c', 1240, 'Aalborg', 440)" ] }, "execution_count": 334, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_holiday()" ] }, { "cell_type": "code", "execution_count": 350, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('06ac3a9503b1', 1227, 'Aalborg', 442),\n", " ('d85f0e60a', 1239, 'Nullarbor', 449),\n", " ('b3a272766a', 1110, 'Morgantown', 509),\n", " ('b6c2aa7e3', 1345, 'Estacada', 424),\n", " ('d4eaa7f8cc8b', 1104, 'Almaty', 484),\n", " ('c317bc9d7cc', 1075, 'Tambon-Pa-Fa', 369),\n", " ('bccde42c0', 1332, 'Lemnos', 493),\n", " ('b0144b482a', 1291, 'Sofia', 481),\n", " ('445c3a850f54', 1237, 'Puente-Laguna-Garzonkuala-Penyu', 480),\n", " ('59d11cd5e4', 1248, 'Hajnowski', 412),\n", " ('df04f8ebcbe', 1043, 'Karlukovo', 476),\n", " ('cd66382b1', 1202, 'Mamula', 365),\n", " ('f134b58dd57b', 1516, 'Stonington-Island', 483),\n", " ('ae72be72d', 1372, 'Grimsey-Island', 376),\n", " ('7526e7e52986', 1356, 'Uzupis', 416),\n", " ('099a5b5615d', 1158, 'Sukhumi', 439),\n", " ('cbcf3eb0953b', 1202, 'Ijsseloog', 444),\n", " ('2e205f2c', 1009, 'Giessenmestia', 426),\n", " ('83ed8adee', 1177, 'Nordkapp', 471),\n", " ('099e6a27a7d', 1238, 'Gorongosa', 441),\n", " ('cb4422b7', 1199, 'Brorfelde', 408),\n", " ('7df5b4b81e', 1452, 'Parowan', 553),\n", " ('78f90135', 1127, 'Tubakuba', 405),\n", " ('1ca8e1b0', 1267, 'Geoje-Si', 440),\n", " ('e1a1fb01', 1551, 'Mora', 479),\n", " ('472c727d38', 1258, 'Holmegaard', 481),\n", " ('1c1e844f72', 1100, 'Jayuya', 412),\n", " ('8c36acb8bd5', 1283, 'Zhangye-Shi', 438),\n", " ('a4c1eba28663', 1405, 'Luoyang', 450)]" ] }, "execution_count": 350, "metadata": {}, "output_type": "execute_result" } ], "source": [ "holidays = []\n", "for n in destination_names:\n", " holidays += [make_holiday(n)]\n", "holidays" ] }, { "cell_type": "code", "execution_count": 336, "metadata": {}, "outputs": [], "source": [ "# holidays = []\n", "# for _ in range(20):\n", "# n = random.choice(few_destination_names)\n", "# holidays += [make_holiday(n)]\n", "# holidays" ] }, { "cell_type": "code", "execution_count": 337, "metadata": { "collapsed": true }, "outputs": [], "source": [ "for _ in range(95):\n", " holidays += [make_holiday()]" ] }, { "cell_type": "code", "execution_count": 361, "metadata": {}, "outputs": [], "source": [ "def best(holidays): \n", " return max(holidays,\n", " key = lambda h: h[1] + max(h[3] - 500, 0))[0]" ] }, { "cell_type": "code", "execution_count": 362, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'a52c279d29'" ] }, "execution_count": 362, "metadata": {}, "output_type": "execute_result" } ], "source": [ "best(holidays)" ] }, { "cell_type": "code", "execution_count": 358, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "443" ] }, "execution_count": 358, "metadata": {}, "output_type": "execute_result" } ], "source": [ "holidays[0][3]" ] }, { "cell_type": "code", "execution_count": 363, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def best_500(holidays): \n", " return max(holidays,\n", " key = lambda h: h[1] + h[3] - 500)[0]" ] }, { "cell_type": "code", "execution_count": 364, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def best_base(holidays): \n", " return max(holidays,\n", " key = lambda h: h[1])[0]" ] }, { "cell_type": "code", "execution_count": 377, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('d7d9600a9018', 984, 'Aalborg', 559),\n", " ('a4fda9ce7e7', 1132, 'Nullarbor', 549),\n", " ('b50b0503', 1169, 'Morgantown', 514),\n", " ('c5d2db28c', 1206, 'Estacada', 565),\n", " ('909acf5b3', 1137, 'Almaty', 599),\n", " ('d21d32624', 1288, 'Tambon-Pa-Fa', 652),\n", " ('b0ca7167f7', 1265, 'Lemnos', 679),\n", " ('88324193b87', 1180, 'Sofia', 597),\n", " ('d053b7fa98', 1125, 'Puente-Laguna-Garzonkuala-Penyu', 621),\n", " ('6e6ee9c06', 1053, 'Hajnowski', 565),\n", " ('a86f98f6d8', 1388, 'Karlukovo', 524),\n", " ('443a80bb', 1286, 'Mamula', 872),\n", " ('cf8876d4e73', 823, 'Stonington-Island', 693),\n", " ('04f3f57cda', 1321, 'Grimsey-Island', 631),\n", " ('b6ef99699d8', 963, 'Uzupis', 549),\n", " ('8255b281', 1302, 'Sukhumi', 542),\n", " ('234cd3dc12de', 1206, 'Ijsseloog', 468),\n", " ('e3790f1484', 1682, 'Giessenmestia', 448),\n", " ('9d478716', 1282, 'Nordkapp', 617),\n", " ('ae037be7d2', 1187, 'Gorongosa', 548),\n", " ('a8240f7292', 1119, 'Brorfelde', 675),\n", " ('90409a70', 1143, 'Parowan', 679),\n", " ('886090a35571', 1428, 'Tubakuba', 575),\n", " ('b6ad98c5c8', 1131, 'Geoje-Si', 502),\n", " ('f38f75c8e4e', 1319, 'Mora', 685),\n", " ('224ec122957', 1164, 'Holmegaard', 545),\n", " ('c4a45e60f', 1078, 'Jayuya', 573),\n", " ('ca574abd1d59', 1201, 'Zhangye-Shi', 559),\n", " ('0d3a5b9861', 1232, 'Luoyang', 547),\n", " ('2781c13abc2', 1057, 'Tubakuba', 561),\n", " ('d77b1148', 1396, 'Mamula', 579),\n", " ('3bc5b60c2a5', 1231, 'Nullarbor', 517),\n", " ('0afe71e09d', 1276, 'Stonington-Island', 640),\n", " ('fed8853e496e', 1098, 'Geoje-Si', 688),\n", " ('fc20a36d036', 928, 'Almaty', 738),\n", " ('05c4bc08fd31', 1210, 'Jayuya', 516),\n", " ('0dc258d3e', 1164, 'Tubakuba', 596),\n", " ('498d42d27', 1095, 'Holmegaard', 562),\n", " ('616a27c7', 942, 'Brorfelde', 639),\n", " ('a46da8767867', 1281, 'Sofia', 598),\n", " ('763db1eb6980', 944, 'Geoje-Si', 707),\n", " ('59ea16ce6364', 1110, 'Grimsey-Island', 711),\n", " ('00f15d691e2c', 1205, 'Estacada', 487),\n", " ('92f4320298', 1093, 'Morgantown', 620),\n", " ('06b34cf1', 1134, 'Nordkapp', 529),\n", " ('83fea1e3', 1365, 'Lemnos', 596),\n", " ('8edd80b3fb1', 1215, 'Brorfelde', 714),\n", " ('2b11e359e8f9', 1488, 'Brorfelde', 613),\n", " ('164cc47ace7c', 1068, 'Zhangye-Shi', 527),\n", " ('70e5c8cd42', 1185, 'Mora', 546),\n", " ('7b2fddd6', 1263, 'Holmegaard', 630),\n", " ('25a2c3799a', 1340, 'Sukhumi', 709),\n", " ('68ac312e3af5', 1421, 'Geoje-Si', 621),\n", " ('63c55129', 1260, 'Stonington-Island', 579),\n", " ('0b4b44db1d', 1089, 'Holmegaard', 591),\n", " ('0b3b738f0', 1226, 'Stonington-Island', 688),\n", " ('a6538cfa970', 1100, 'Parowan', 661),\n", " ('1634bfe2408', 1264, 'Giessenmestia', 460),\n", " ('7c2e49058b', 1022, 'Estacada', 509),\n", " ('f02bc3375', 1225, 'Tubakuba', 569),\n", " ('be8b9d110', 984, 'Tubakuba', 485),\n", " ('627824317b47', 909, 'Giessenmestia', 532),\n", " ('476cd20cca', 1046, 'Nullarbor', 648),\n", " ('44e58004d2', 1206, 'Karlukovo', 526),\n", " ('d00ab6e33', 1167, 'Sofia', 574),\n", " ('1c5f5ecd6a', 1332, 'Holmegaard', 615),\n", " ('9557b5625e4', 1242, 'Puente-Laguna-Garzonkuala-Penyu', 622),\n", " ('34f1e2873504', 1042, 'Giessenmestia', 572),\n", " ('b9ac3a5e', 961, 'Grimsey-Island', 663),\n", " ('11ea654a37dc', 1306, 'Tambon-Pa-Fa', 653),\n", " ('113bdf3f311', 1167, 'Grimsey-Island', 615),\n", " ('b450fed871', 1244, 'Luoyang', 584),\n", " ('e4964650f', 1093, 'Karlukovo', 675),\n", " ('f3c42695', 1241, 'Nordkapp', 751),\n", " ('61e833fb', 1158, 'Sukhumi', 502),\n", " ('146c154627', 1321, 'Parowan', 658),\n", " ('d4ab30071b', 895, 'Nullarbor', 589),\n", " ('2f3d30dd1d9', 1230, 'Lemnos', 679),\n", " ('f793130d4b2d', 1473, 'Nordkapp', 595),\n", " ('c0f9ca8f476', 1186, 'Zhangye-Shi', 660),\n", " ('bfd6cbaf09e1', 898, 'Nullarbor', 615),\n", " ('829cc66f6524', 1254, 'Luoyang', 651),\n", " ('0fe6b54be76', 1318, 'Sukhumi', 591),\n", " ('a3169c6312', 1364, 'Sofia', 631),\n", " ('2a57e5b6bff', 1203, 'Geoje-Si', 624),\n", " ('e29a171ab', 1278, 'Lemnos', 602),\n", " ('03478ddc6', 1119, 'Hajnowski', 599),\n", " ('1cb8cefaab4', 1278, 'Gorongosa', 606),\n", " ('f7566ec36', 972, 'Uzupis', 538),\n", " ('34f4312fdd0', 1121, 'Grimsey-Island', 644),\n", " ('d2719728360', 1145, 'Tambon-Pa-Fa', 727),\n", " ('89e60557edd', 1345, 'Hajnowski', 565),\n", " ('66ffcd848', 974, 'Nullarbor', 707),\n", " ('7cfb6f85', 969, 'Grimsey-Island', 589),\n", " ('f22c113c', 1217, 'Mamula', 521),\n", " ('647315ef', 824, 'Uzupis', 668),\n", " ('42e05169e', 1104, 'Jayuya', 476),\n", " ('e0862b3984ce', 1270, 'Morgantown', 565),\n", " ('355f35a449d', 1061, 'Sofia', 539),\n", " ('a68d97fbfdb', 987, 'Brorfelde', 459),\n", " ('3de94090', 1149, 'Tambon-Pa-Fa', 590),\n", " ('24ebbe60', 1331, 'Estacada', 628),\n", " ('4b9291505', 1230, 'Giessenmestia', 648),\n", " ('52e1d5566142', 1173, 'Ijsseloog', 721),\n", " ('d4bc8ebfb', 1373, 'Mamula', 651),\n", " ('d7bcc37c902b', 1127, 'Giessenmestia', 520),\n", " ('71772664d35c', 1205, 'Geoje-Si', 615),\n", " ('94d98461f6', 1179, 'Almaty', 496),\n", " ('f87121d062', 1127, 'Karlukovo', 502),\n", " ('cdd546172', 1221, 'Puente-Laguna-Garzonkuala-Penyu', 593),\n", " ('cf38d8107', 1073, 'Nullarbor', 613),\n", " ('cd563561', 1136, 'Nordkapp', 634),\n", " ('13d8d416d', 1328, 'Giessenmestia', 590),\n", " ('1b38b7b4d94', 1205, 'Aalborg', 660),\n", " ('cd1f4025', 1419, 'Mamula', 629),\n", " ('382daab54', 1461, 'Nullarbor', 601),\n", " ('22b8e494f', 1029, 'Nullarbor', 623),\n", " ('da517616ec', 1272, 'Gorongosa', 520),\n", " ('0ab5ce808111', 1268, 'Gorongosa', 542),\n", " ('ced9502128', 1077, 'Ijsseloog', 576),\n", " ('83a7d0bbd1', 1225, 'Aalborg', 689),\n", " ('18e93a0f0c', 918, 'Ijsseloog', 560),\n", " ('7f98bd73d5cc', 1125, 'Nordkapp', 628),\n", " ('ddc31baf1', 1175, 'Puente-Laguna-Garzonkuala-Penyu', 612)]" ] }, "execution_count": 377, "metadata": {}, "output_type": "execute_result" } ], "source": [ "finished = False\n", "while not finished:\n", "# print('iterating')\n", " holidays = []\n", " for n in destination_names:\n", " holidays += [make_holiday(n)]\n", " for _ in range(95):\n", " holidays += [make_holiday()]\n", " finished = ((len(set(h[0] for h in holidays)) == len(holidays)) and \n", " len(set([best(holidays), \n", " best_500(holidays), \n", "# best_base(holidays)\n", " ])) >= 2\n", "# True\n", " )\n", "holidays" ] }, { "cell_type": "code", "execution_count": 378, "metadata": { "collapsed": true }, "outputs": [], "source": [ "random.shuffle(holidays)\n", "with open('00-prices.txt', 'w') as f:\n", " for hid, price, name, days in holidays:\n", " f.write('{} {} {} {}\\n'.format(hid, price, name, days))" ] }, { "cell_type": "code", "execution_count": 376, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['9bbe30d6', '1253', 'Brorfelde', '604'],\n", " ['a6f792b85035', '1104', 'Estacada', '681'],\n", " ['337f1026e1', '1372', 'Karlukovo', '585']]" ] }, "execution_count": 376, "metadata": {}, "output_type": "execute_result" } ], "source": [ "with open('00-prices.txt') as f:\n", " hols = [h.split() for h in f.readlines()]\n", "hols[:3]" ] }, { "cell_type": "code", "execution_count": 341, "metadata": { "collapsed": true }, "outputs": [], "source": [ "assert len(set(h[0] for h in hols)) == len(hols)" ] }, { "cell_type": "code", "execution_count": 342, "metadata": { "collapsed": true }, "outputs": [], "source": [ "example_holidays = [('f2ffe169-7cc5-42e1-9b46-8cdb61bb906d', 769, 'Morgantown', 3),\n", " ('2e6a6d6d-6c08-4021-b99f-05202c898b5f', 1284, 'Morgantown', 21),\n", " ('ab659b71-347d-45dc-9416-34def36ffc7d', 1514, 'Giessenmestia', 21),\n", " ('eafb15a4-1839-4fb5-be9b-d8389018bd07', 1052, 'Estacada', 21),\n", " ('7476b214-8b55-47f6-833e-dfa487c4270a', 782, 'Geoje-Si', 14),\n", " ('bb8d5034-49ce-483d-ab6c-d16caf2584a5', 724, 'Stonington-Island', 14),\n", " ('6138068a-3c16-4f7f-8dc6-a1199608abc5', 1209, 'Nordkapp', 21)]" ] }, { "cell_type": "code", "execution_count": 343, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "f2ffe169-7cc5-42e1-9b46-8cdb61bb906d 769 Morgantown 3\n", "2e6a6d6d-6c08-4021-b99f-05202c898b5f 1284 Morgantown 21\n", "ab659b71-347d-45dc-9416-34def36ffc7d 1514 Giessenmestia 21\n", "eafb15a4-1839-4fb5-be9b-d8389018bd07 1052 Estacada 21\n", "7476b214-8b55-47f6-833e-dfa487c4270a 782 Geoje-Si 14\n", "bb8d5034-49ce-483d-ab6c-d16caf2584a5 724 Stonington-Island 14\n", "6138068a-3c16-4f7f-8dc6-a1199608abc5 1209 Nordkapp 21\n" ] } ], "source": [ "for hid, price, name, days in example_holidays:\n", " print('{} {} {} {}'.format(hid, price, name, days))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2+" } }, "nbformat": 4, "nbformat_minor": 2 }