{ "cells": [ { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import division\n", "# we have 13 virtual mice, mouse number 0,4,8 are \"empty\" mice.\n", "wine_groups_for_virtual_mice = [set() for i in range(13)]\n", "for i in range(1000):\n", " i0 = i%80\n", " i1 = i0%4\n", " i2 = (i0//4)%4\n", " i3 = i0//16\n", " wine_groups_for_virtual_mice[i1].add(i)\n", " wine_groups_for_virtual_mice[4+i2].add(i)\n", " wine_groups_for_virtual_mice[8+i3].add(i)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140, 144, 145, 146, 148, 160, 161, 162, 164, 256, 257, 258, 260, 264, 265, 266, 268, 272, 273, 274, 276, 288, 289, 290, 292, 512, 513, 514, 516, 520, 521, 522, 524, 528, 529, 530, 532, 544, 545, 546, 548, 0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18, 20, 32, 33, 34, 36, 64, 65, 66, 68, 72, 73, 74, 76, 80, 81, 82, 84, 96, 97, 98, 100, 128, 129, 130, 132, 136, 137, 138, 140]\n" ] } ], "source": [ "encodings=[0]*1000\n", "j = 1\n", "for i in range(13):\n", " if i not in [0,4,8]:\n", " for w in wine_groups_for_virtual_mice[i]:\n", " encodings[w]|=j\n", " j<<=1\n", "print(encodings)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [], "source": [ "wine_groups_for_real_mice=[ set() if i in [0,4,8] else wine_groups_for_virtual_mice[i] for i in range(13)]" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def test_result(poison_wine):\n", " return [bool(poison_wine&w) for w in wine_groups_for_real_mice]" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def make_decision(result):\n", " r = result[:]\n", " r[0] = sum(r[:4])<2\n", " r[4] = sum(r[4:8])<2\n", " r[8] = sum(r[8:])<2\n", " g1, g2, g3 = set(), set(), set()\n", " for i in range(4):\n", " if r[i]:\n", " g1 |= wine_groups_for_virtual_mice[i]\n", " for i in range(4,8):\n", " if r[i]:\n", " g2 |= wine_groups_for_virtual_mice[i]\n", " for i in range(8,13):\n", " if r[i]:\n", " g3 |= wine_groups_for_virtual_mice[i]\n", " return g1 & g2 & g3\n", "\n", "def verify(poison_wine, decision):\n", " return poison_wine <= decision\n", " " ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(0, 0)\n", "(10, 104)\n", "(20, 104)\n", "(30, 104)\n", "(40, 104)\n", "(50, 104)\n", "(60, 104)\n", "(70, 104)\n", "(80, 104)\n", "(90, 104)\n", "(100, 104)\n", "(110, 104)\n", "(120, 104)\n", "(130, 104)\n", "(140, 104)\n", "(150, 104)\n", "(160, 104)\n", "(170, 104)\n", "(180, 104)\n", "(190, 104)\n", "(200, 104)\n", "(210, 104)\n", "(220, 104)\n", "(230, 104)\n", "(240, 104)\n", "(250, 104)\n", "(260, 104)\n", "(270, 104)\n", "(280, 104)\n", "(290, 104)\n", "(300, 104)\n", "(310, 104)\n", "(320, 104)\n", "(330, 104)\n", "(340, 104)\n", "(350, 104)\n", "(360, 104)\n", "(370, 104)\n", "(380, 104)\n", "(390, 104)\n", "(400, 104)\n", "(410, 104)\n", "(420, 104)\n", "(430, 104)\n", "(440, 104)\n", "(450, 104)\n", "(460, 104)\n", "(470, 104)\n", "(480, 104)\n", "(490, 104)\n", "(500, 104)\n", "(510, 104)\n", "(520, 104)\n", "(530, 104)\n", "(540, 104)\n", "(550, 104)\n", "(560, 104)\n", "(570, 104)\n", "(580, 104)\n", "(590, 104)\n", "(600, 104)\n", "(610, 104)\n", "(620, 104)\n", "(630, 104)\n", "(640, 104)\n", "(650, 104)\n", "(660, 104)\n", "(670, 104)\n", "(680, 104)\n", "(690, 104)\n", "(700, 104)\n", "(710, 104)\n", "(720, 104)\n", "(730, 104)\n", "(740, 104)\n", "(750, 104)\n", "(760, 104)\n", "(770, 104)\n", "(780, 104)\n", "(790, 104)\n", "(800, 104)\n", "(810, 104)\n", "(820, 104)\n", "(830, 104)\n", "(840, 104)\n", "(850, 104)\n", "(860, 104)\n", "(870, 104)\n", "(880, 104)\n", "(890, 104)\n", "(900, 104)\n", "(910, 104)\n", "(920, 104)\n", "(930, 104)\n", "(940, 104)\n", "(950, 104)\n", "(960, 104)\n", "(970, 104)\n", "(980, 104)\n", "(990, 104)\n", "done\n" ] } ], "source": [ "m = 0\n", "for i in range(999):\n", " if i%10==0:\n", " print(i,m)\n", " for j in range(i,1000):\n", " poison = {i,j}\n", " result = test_result(poison) \n", " decision = make_decision(result)\n", " if len(decision) > 104 or not verify(poison, decision):\n", " print(i,j, len(decision)) \n", " break\n", " m = max(len(decision), m)\n", "print(\"done\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }