--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "import itertools\n",
+ "import functools\n",
+ "import operator\n",
+ "\n",
+ "def prod(iterable):\n",
+ " return functools.reduce(operator.mul, iterable, 1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[1,\n",
+ " 2,\n",
+ " 3,\n",
+ " 5,\n",
+ " 7,\n",
+ " 13,\n",
+ " 17,\n",
+ " 19,\n",
+ " 23,\n",
+ " 29,\n",
+ " 31,\n",
+ " 37,\n",
+ " 41,\n",
+ " 43,\n",
+ " 53,\n",
+ " 59,\n",
+ " 61,\n",
+ " 67,\n",
+ " 71,\n",
+ " 73,\n",
+ " 79,\n",
+ " 83,\n",
+ " 89,\n",
+ " 97,\n",
+ " 101,\n",
+ " 103,\n",
+ " 107,\n",
+ " 109,\n",
+ " 113]"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "presents = [int(p) for p in open('advent24.txt').readlines()]\n",
+ "presents"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "# presents = [1,2,3,4,5,7,8,9,10,11]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "512"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "group_weight = sum(presents) // 3\n",
+ "group_weight"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "#def valid(g1, g2, g3):\n",
+ "# return len(g1) < len(g2) and len(g1) < len(g3) and \\\n",
+ "# not (g1 & g2) and not (g1 & g3) and not (g2 & g3)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[([9, 11], [1, 2, 3, 4, 10], [5, 7, 8]),\n",
+ " ([9, 11], [1, 2, 3, 4, 10], [5, 8, 7]),\n",
+ " ([9, 11], [1, 2, 3, 4, 10], [7, 5, 8]),\n",
+ " ([9, 11], [1, 2, 3, 4, 10], [7, 8, 5]),\n",
+ " ([9, 11], [1, 2, 3, 4, 10], [8, 5, 7]),\n",
+ " ([9, 11], [1, 2, 3, 4, 10], [8, 7, 5]),\n",
+ " ([9, 11], [1, 2, 3, 10, 4], [5, 7, 8]),\n",
+ " ([9, 11], [1, 2, 3, 10, 4], [5, 8, 7]),\n",
+ " ([9, 11], [1, 2, 3, 10, 4], [7, 5, 8]),\n",
+ " ([9, 11], [1, 2, 3, 10, 4], [7, 8, 5]),\n",
+ " ([9, 11], [1, 2, 3, 10, 4], [8, 5, 7]),\n",
+ " ([9, 11], [1, 2, 3, 10, 4], [8, 7, 5]),\n",
+ " ([9, 11], [1, 2, 4, 3, 10], [5, 7, 8]),\n",
+ " ([9, 11], [1, 2, 4, 3, 10], [5, 8, 7]),\n",
+ " ([9, 11], [1, 2, 4, 3, 10], [7, 5, 8]),\n",
+ " ([9, 11], [1, 2, 4, 3, 10], [7, 8, 5]),\n",
+ " ([9, 11], [1, 2, 4, 3, 10], [8, 5, 7]),\n",
+ " ([9, 11], [1, 2, 4, 3, 10], [8, 7, 5]),\n",
+ " ([9, 11], [1, 2, 4, 5, 8], [3, 7, 10]),\n",
+ " ([9, 11], [1, 2, 4, 5, 8], [3, 10, 7]),\n",
+ " ([9, 11], [1, 2, 4, 5, 8], [7, 3, 10]),\n",
+ " ([9, 11], [1, 2, 4, 5, 8], [7, 10, 3]),\n",
+ " ([9, 11], [1, 2, 4, 5, 8], [10, 3, 7]),\n",
+ " ([9, 11], [1, 2, 4, 5, 8], [10, 7, 3]),\n",
+ " ([9, 11], [1, 2, 4, 8, 5], [3, 7, 10]),\n",
+ " ([9, 11], [1, 2, 4, 8, 5], [3, 10, 7]),\n",
+ " ([9, 11], [1, 2, 4, 8, 5], [7, 3, 10]),\n",
+ " ([9, 11], [1, 2, 4, 8, 5], [7, 10, 3]),\n",
+ " ([9, 11], [1, 2, 4, 8, 5], [10, 3, 7]),\n",
+ " ([9, 11], [1, 2, 4, 8, 5], [10, 7, 3]),\n",
+ " ([9, 11], [1, 2, 4, 10, 3], [5, 7, 8]),\n",
+ " ([9, 11], [1, 2, 4, 10, 3], [5, 8, 7]),\n",
+ " ([9, 11], [1, 2, 4, 10, 3], [7, 5, 8]),\n",
+ " ([9, 11], [1, 2, 4, 10, 3], [7, 8, 5]),\n",
+ " ([9, 11], [1, 2, 4, 10, 3], [8, 5, 7]),\n",
+ " ([9, 11], [1, 2, 4, 10, 3], [8, 7, 5]),\n",
+ " ([9, 11], [1, 2, 5, 4, 8], [3, 7, 10]),\n",
+ " ([9, 11], [1, 2, 5, 4, 8], [3, 10, 7]),\n",
+ " ([9, 11], [1, 2, 5, 4, 8], [7, 3, 10]),\n",
+ " ([9, 11], [1, 2, 5, 4, 8], [7, 10, 3]),\n",
+ " ([9, 11], [1, 2, 5, 4, 8], [10, 3, 7]),\n",
+ " ([9, 11], [1, 2, 5, 4, 8], [10, 7, 3]),\n",
+ " ([9, 11], [1, 2, 5, 8, 4], [3, 7, 10]),\n",
+ " ([9, 11], [1, 2, 5, 8, 4], [3, 10, 7]),\n",
+ " ([9, 11], [1, 2, 5, 8, 4], [7, 3, 10]),\n",
+ " ([9, 11], [1, 2, 5, 8, 4], [7, 10, 3]),\n",
+ " ([9, 11], [1, 2, 5, 8, 4], [10, 3, 7]),\n",
+ " ([9, 11], [1, 2, 5, 8, 4], [10, 7, 3]),\n",
+ " ([9, 11], [1, 2, 7, 10], [3, 4, 5, 8]),\n",
+ " ([9, 11], [1, 2, 7, 10], [3, 4, 8, 5]),\n",
+ " ([9, 11], [1, 2, 7, 10], [3, 5, 4, 8]),\n",
+ " ([9, 11], [1, 2, 7, 10], [3, 5, 8, 4]),\n",
+ " ([9, 11], [1, 2, 7, 10], [3, 8, 4, 5]),\n",
+ " ([9, 11], [1, 2, 7, 10], [3, 8, 5, 4]),\n",
+ " ([9, 11], [1, 2, 7, 10], [4, 3, 5, 8]),\n",
+ " ([9, 11], [1, 2, 7, 10], [4, 3, 8, 5]),\n",
+ " ([9, 11], [1, 2, 7, 10], [4, 5, 3, 8]),\n",
+ " ([9, 11], [1, 2, 7, 10], [4, 5, 8, 3]),\n",
+ " ([9, 11], [1, 2, 7, 10], [4, 8, 3, 5]),\n",
+ " ([9, 11], [1, 2, 7, 10], [4, 8, 5, 3]),\n",
+ " ([9, 11], [1, 2, 7, 10], [5, 3, 4, 8]),\n",
+ " ([9, 11], [1, 2, 7, 10], [5, 3, 8, 4]),\n",
+ " ([9, 11], [1, 2, 7, 10], [5, 4, 3, 8]),\n",
+ " ([9, 11], [1, 2, 7, 10], [5, 4, 8, 3]),\n",
+ " ([9, 11], [1, 2, 7, 10], [5, 8, 3, 4]),\n",
+ " ([9, 11], [1, 2, 7, 10], [5, 8, 4, 3]),\n",
+ " ([9, 11], [1, 2, 7, 10], [8, 3, 4, 5]),\n",
+ " ([9, 11], [1, 2, 7, 10], [8, 3, 5, 4]),\n",
+ " ([9, 11], [1, 2, 7, 10], [8, 4, 3, 5]),\n",
+ " ([9, 11], [1, 2, 7, 10], [8, 4, 5, 3]),\n",
+ " ([9, 11], [1, 2, 7, 10], [8, 5, 3, 4]),\n",
+ " ([9, 11], [1, 2, 7, 10], [8, 5, 4, 3]),\n",
+ " ([9, 11], [1, 2, 8, 4, 5], [3, 7, 10]),\n",
+ " ([9, 11], [1, 2, 8, 4, 5], [3, 10, 7]),\n",
+ " ([9, 11], [1, 2, 8, 4, 5], [7, 3, 10]),\n",
+ " ([9, 11], [1, 2, 8, 4, 5], [7, 10, 3]),\n",
+ " ([9, 11], [1, 2, 8, 4, 5], [10, 3, 7]),\n",
+ " ([9, 11], [1, 2, 8, 4, 5], [10, 7, 3]),\n",
+ " ([9, 11], [1, 2, 8, 5, 4], [3, 7, 10]),\n",
+ " ([9, 11], [1, 2, 8, 5, 4], [3, 10, 7]),\n",
+ " ([9, 11], [1, 2, 8, 5, 4], [7, 3, 10]),\n",
+ " ([9, 11], [1, 2, 8, 5, 4], [7, 10, 3]),\n",
+ " ([9, 11], [1, 2, 8, 5, 4], [10, 3, 7]),\n",
+ " ([9, 11], [1, 2, 8, 5, 4], [10, 7, 3]),\n",
+ " ([9, 11], [1, 2, 10, 3, 4], [5, 7, 8]),\n",
+ " ([9, 11], [1, 2, 10, 3, 4], [5, 8, 7]),\n",
+ " ([9, 11], [1, 2, 10, 3, 4], [7, 5, 8]),\n",
+ " ([9, 11], [1, 2, 10, 3, 4], [7, 8, 5]),\n",
+ " ([9, 11], [1, 2, 10, 3, 4], [8, 5, 7]),\n",
+ " ([9, 11], [1, 2, 10, 3, 4], [8, 7, 5]),\n",
+ " ([9, 11], [1, 2, 10, 4, 3], [5, 7, 8]),\n",
+ " ([9, 11], [1, 2, 10, 4, 3], [5, 8, 7]),\n",
+ " ([9, 11], [1, 2, 10, 4, 3], [7, 5, 8]),\n",
+ " ([9, 11], [1, 2, 10, 4, 3], [7, 8, 5]),\n",
+ " ([9, 11], [1, 2, 10, 4, 3], [8, 5, 7]),\n",
+ " ([9, 11], [1, 2, 10, 4, 3], [8, 7, 5]),\n",
+ " ([9, 11], [1, 2, 10, 7], [3, 4, 5, 8]),\n",
+ " ([9, 11], [1, 2, 10, 7], [3, 4, 8, 5]),\n",
+ " ([9, 11], [1, 2, 10, 7], [3, 5, 4, 8]),\n",
+ " ([9, 11], [1, 2, 10, 7], [3, 5, 8, 4]),\n",
+ " ([9, 11], [1, 2, 10, 7], [3, 8, 4, 5]),\n",
+ " ([9, 11], [1, 2, 10, 7], [3, 8, 5, 4]),\n",
+ " ([9, 11], [1, 2, 10, 7], [4, 3, 5, 8]),\n",
+ " ([9, 11], [1, 2, 10, 7], [4, 3, 8, 5]),\n",
+ " ([9, 11], [1, 2, 10, 7], [4, 5, 3, 8]),\n",
+ " ([9, 11], [1, 2, 10, 7], [4, 5, 8, 3]),\n",
+ " ([9, 11], [1, 2, 10, 7], [4, 8, 3, 5]),\n",
+ " ([9, 11], [1, 2, 10, 7], [4, 8, 5, 3]),\n",
+ " ([9, 11], [1, 2, 10, 7], [5, 3, 4, 8]),\n",
+ " ([9, 11], [1, 2, 10, 7], [5, 3, 8, 4]),\n",
+ " ([9, 11], [1, 2, 10, 7], [5, 4, 3, 8]),\n",
+ " ([9, 11], [1, 2, 10, 7], [5, 4, 8, 3]),\n",
+ " ([9, 11], [1, 2, 10, 7], [5, 8, 3, 4]),\n",
+ " ([9, 11], [1, 2, 10, 7], [5, 8, 4, 3]),\n",
+ " ([9, 11], [1, 2, 10, 7], [8, 3, 4, 5]),\n",
+ " ([9, 11], [1, 2, 10, 7], [8, 3, 5, 4]),\n",
+ " ([9, 11], [1, 2, 10, 7], [8, 4, 3, 5]),\n",
+ " ([9, 11], [1, 2, 10, 7], [8, 4, 5, 3]),\n",
+ " ([9, 11], [1, 2, 10, 7], [8, 5, 3, 4]),\n",
+ " ([9, 11], [1, 2, 10, 7], [8, 5, 4, 3]),\n",
+ " ([9, 11], [1, 3, 2, 4, 10], [5, 7, 8]),\n",
+ " ([9, 11], [1, 3, 2, 4, 10], [5, 8, 7]),\n",
+ " ([9, 11], [1, 3, 2, 4, 10], [7, 5, 8]),\n",
+ " ([9, 11], [1, 3, 2, 4, 10], [7, 8, 5]),\n",
+ " ([9, 11], [1, 3, 2, 4, 10], [8, 5, 7]),\n",
+ " ([9, 11], [1, 3, 2, 4, 10], [8, 7, 5]),\n",
+ " ([9, 11], [1, 3, 2, 10, 4], [5, 7, 8]),\n",
+ " ([9, 11], [1, 3, 2, 10, 4], [5, 8, 7]),\n",
+ " ([9, 11], [1, 3, 2, 10, 4], [7, 5, 8]),\n",
+ " ([9, 11], [1, 3, 2, 10, 4], [7, 8, 5]),\n",
+ " ([9, 11], [1, 3, 2, 10, 4], [8, 5, 7]),\n",
+ " ([9, 11], [1, 3, 2, 10, 4], [8, 7, 5]),\n",
+ " ([9, 11], [1, 3, 4, 2, 10], [5, 7, 8]),\n",
+ " ([9, 11], [1, 3, 4, 2, 10], [5, 8, 7]),\n",
+ " ([9, 11], [1, 3, 4, 2, 10], [7, 5, 8]),\n",
+ " ([9, 11], [1, 3, 4, 2, 10], [7, 8, 5]),\n",
+ " ([9, 11], [1, 3, 4, 2, 10], [8, 5, 7]),\n",
+ " ([9, 11], [1, 3, 4, 2, 10], [8, 7, 5]),\n",
+ " ([9, 11], [1, 3, 4, 5, 7], [2, 8, 10]),\n",
+ " ([9, 11], [1, 3, 4, 5, 7], [2, 10, 8]),\n",
+ " ([9, 11], [1, 3, 4, 5, 7], [8, 2, 10]),\n",
+ " ([9, 11], [1, 3, 4, 5, 7], [8, 10, 2]),\n",
+ " ([9, 11], [1, 3, 4, 5, 7], [10, 2, 8]),\n",
+ " ([9, 11], [1, 3, 4, 5, 7], [10, 8, 2]),\n",
+ " ([9, 11], [1, 3, 4, 7, 5], [2, 8, 10]),\n",
+ " ([9, 11], [1, 3, 4, 7, 5], [2, 10, 8]),\n",
+ " ([9, 11], [1, 3, 4, 7, 5], [8, 2, 10]),\n",
+ " ([9, 11], [1, 3, 4, 7, 5], [8, 10, 2]),\n",
+ " ([9, 11], [1, 3, 4, 7, 5], [10, 2, 8]),\n",
+ " ([9, 11], [1, 3, 4, 7, 5], [10, 8, 2]),\n",
+ " ([9, 11], [1, 3, 4, 10, 2], [5, 7, 8]),\n",
+ " ([9, 11], [1, 3, 4, 10, 2], [5, 8, 7]),\n",
+ " ([9, 11], [1, 3, 4, 10, 2], [7, 5, 8]),\n",
+ " ([9, 11], [1, 3, 4, 10, 2], [7, 8, 5]),\n",
+ " ([9, 11], [1, 3, 4, 10, 2], [8, 5, 7]),\n",
+ " ([9, 11], [1, 3, 4, 10, 2], [8, 7, 5]),\n",
+ " ([9, 11], [1, 3, 5, 4, 7], [2, 8, 10]),\n",
+ " ([9, 11], [1, 3, 5, 4, 7], [2, 10, 8]),\n",
+ " ([9, 11], [1, 3, 5, 4, 7], [8, 2, 10]),\n",
+ " ([9, 11], [1, 3, 5, 4, 7], [8, 10, 2]),\n",
+ " ([9, 11], [1, 3, 5, 4, 7], [10, 2, 8]),\n",
+ " ([9, 11], [1, 3, 5, 4, 7], [10, 8, 2]),\n",
+ " ([9, 11], [1, 3, 5, 7, 4], [2, 8, 10]),\n",
+ " ([9, 11], [1, 3, 5, 7, 4], [2, 10, 8]),\n",
+ " ([9, 11], [1, 3, 5, 7, 4], [8, 2, 10]),\n",
+ " ([9, 11], [1, 3, 5, 7, 4], [8, 10, 2]),\n",
+ " ([9, 11], [1, 3, 5, 7, 4], [10, 2, 8]),\n",
+ " ([9, 11], [1, 3, 5, 7, 4], [10, 8, 2]),\n",
+ " ([9, 11], [1, 3, 7, 4, 5], [2, 8, 10]),\n",
+ " ([9, 11], [1, 3, 7, 4, 5], [2, 10, 8]),\n",
+ " ([9, 11], [1, 3, 7, 4, 5], [8, 2, 10]),\n",
+ " ([9, 11], [1, 3, 7, 4, 5], [8, 10, 2]),\n",
+ " ([9, 11], [1, 3, 7, 4, 5], [10, 2, 8]),\n",
+ " ([9, 11], [1, 3, 7, 4, 5], [10, 8, 2]),\n",
+ " ([9, 11], [1, 3, 7, 5, 4], [2, 8, 10]),\n",
+ " ([9, 11], [1, 3, 7, 5, 4], [2, 10, 8]),\n",
+ " ([9, 11], [1, 3, 7, 5, 4], [8, 2, 10]),\n",
+ " ([9, 11], [1, 3, 7, 5, 4], [8, 10, 2]),\n",
+ " ([9, 11], [1, 3, 7, 5, 4], [10, 2, 8]),\n",
+ " ([9, 11], [1, 3, 7, 5, 4], [10, 8, 2]),\n",
+ " ([9, 11], [1, 3, 10, 2, 4], [5, 7, 8]),\n",
+ " ([9, 11], [1, 3, 10, 2, 4], [5, 8, 7]),\n",
+ " ([9, 11], [1, 3, 10, 2, 4], [7, 5, 8]),\n",
+ " ([9, 11], [1, 3, 10, 2, 4], [7, 8, 5]),\n",
+ " ([9, 11], [1, 3, 10, 2, 4], [8, 5, 7]),\n",
+ " ([9, 11], [1, 3, 10, 2, 4], [8, 7, 5]),\n",
+ " ([9, 11], [1, 3, 10, 4, 2], [5, 7, 8]),\n",
+ " ([9, 11], [1, 3, 10, 4, 2], [5, 8, 7]),\n",
+ " ([9, 11], [1, 3, 10, 4, 2], [7, 5, 8]),\n",
+ " ([9, 11], [1, 3, 10, 4, 2], [7, 8, 5]),\n",
+ " ([9, 11], [1, 3, 10, 4, 2], [8, 5, 7]),\n",
+ " ([9, 11], [1, 3, 10, 4, 2], [8, 7, 5]),\n",
+ " ([9, 11], [1, 4, 2, 3, 10], [5, 7, 8]),\n",
+ " ([9, 11], [1, 4, 2, 3, 10], [5, 8, 7]),\n",
+ " ([9, 11], [1, 4, 2, 3, 10], [7, 5, 8]),\n",
+ " ([9, 11], [1, 4, 2, 3, 10], [7, 8, 5]),\n",
+ " ([9, 11], [1, 4, 2, 3, 10], [8, 5, 7]),\n",
+ " ([9, 11], [1, 4, 2, 3, 10], [8, 7, 5]),\n",
+ " ([9, 11], [1, 4, 2, 5, 8], [3, 7, 10]),\n",
+ " ([9, 11], [1, 4, 2, 5, 8], [3, 10, 7]),\n",
+ " ([9, 11], [1, 4, 2, 5, 8], [7, 3, 10]),\n",
+ " ([9, 11], [1, 4, 2, 5, 8], [7, 10, 3]),\n",
+ " ([9, 11], [1, 4, 2, 5, 8], [10, 3, 7]),\n",
+ " ([9, 11], [1, 4, 2, 5, 8], [10, 7, 3]),\n",
+ " ([9, 11], [1, 4, 2, 8, 5], [3, 7, 10]),\n",
+ " ([9, 11], [1, 4, 2, 8, 5], [3, 10, 7]),\n",
+ " ([9, 11], [1, 4, 2, 8, 5], [7, 3, 10]),\n",
+ " ([9, 11], [1, 4, 2, 8, 5], [7, 10, 3]),\n",
+ " ([9, 11], [1, 4, 2, 8, 5], [10, 3, 7]),\n",
+ " ([9, 11], [1, 4, 2, 8, 5], [10, 7, 3]),\n",
+ " ([9, 11], [1, 4, 2, 10, 3], [5, 7, 8]),\n",
+ " ([9, 11], [1, 4, 2, 10, 3], [5, 8, 7]),\n",
+ " ([9, 11], [1, 4, 2, 10, 3], [7, 5, 8]),\n",
+ " ([9, 11], [1, 4, 2, 10, 3], [7, 8, 5]),\n",
+ " ([9, 11], [1, 4, 2, 10, 3], [8, 5, 7]),\n",
+ " ([9, 11], [1, 4, 2, 10, 3], [8, 7, 5]),\n",
+ " ([9, 11], [1, 4, 3, 2, 10], [5, 7, 8]),\n",
+ " ([9, 11], [1, 4, 3, 2, 10], [5, 8, 7]),\n",
+ " ([9, 11], [1, 4, 3, 2, 10], [7, 5, 8]),\n",
+ " ([9, 11], [1, 4, 3, 2, 10], [7, 8, 5]),\n",
+ " ([9, 11], [1, 4, 3, 2, 10], [8, 5, 7]),\n",
+ " ([9, 11], [1, 4, 3, 2, 10], [8, 7, 5]),\n",
+ " ([9, 11], [1, 4, 3, 5, 7], [2, 8, 10]),\n",
+ " ([9, 11], [1, 4, 3, 5, 7], [2, 10, 8]),\n",
+ " ([9, 11], [1, 4, 3, 5, 7], [8, 2, 10]),\n",
+ " ([9, 11], [1, 4, 3, 5, 7], [8, 10, 2]),\n",
+ " ([9, 11], [1, 4, 3, 5, 7], [10, 2, 8]),\n",
+ " ([9, 11], [1, 4, 3, 5, 7], [10, 8, 2]),\n",
+ " ([9, 11], [1, 4, 3, 7, 5], [2, 8, 10]),\n",
+ " ([9, 11], [1, 4, 3, 7, 5], [2, 10, 8]),\n",
+ " ([9, 11], [1, 4, 3, 7, 5], [8, 2, 10]),\n",
+ " ([9, 11], [1, 4, 3, 7, 5], [8, 10, 2]),\n",
+ " ([9, 11], [1, 4, 3, 7, 5], [10, 2, 8]),\n",
+ " ([9, 11], [1, 4, 3, 7, 5], [10, 8, 2]),\n",
+ " ([9, 11], [1, 4, 3, 10, 2], [5, 7, 8]),\n",
+ " ([9, 11], [1, 4, 3, 10, 2], [5, 8, 7]),\n",
+ " ([9, 11], [1, 4, 3, 10, 2], [7, 5, 8]),\n",
+ " ([9, 11], [1, 4, 3, 10, 2], [7, 8, 5]),\n",
+ " ([9, 11], [1, 4, 3, 10, 2], [8, 5, 7]),\n",
+ " ([9, 11], [1, 4, 3, 10, 2], [8, 7, 5]),\n",
+ " ([9, 11], [1, 4, 5, 2, 8], [3, 7, 10]),\n",
+ " ([9, 11], [1, 4, 5, 2, 8], [3, 10, 7]),\n",
+ " ([9, 11], [1, 4, 5, 2, 8], [7, 3, 10]),\n",
+ " ([9, 11], [1, 4, 5, 2, 8], [7, 10, 3]),\n",
+ " ([9, 11], [1, 4, 5, 2, 8], [10, 3, 7]),\n",
+ " ([9, 11], [1, 4, 5, 2, 8], [10, 7, 3]),\n",
+ " ([9, 11], [1, 4, 5, 3, 7], [2, 8, 10]),\n",
+ " ([9, 11], [1, 4, 5, 3, 7], [2, 10, 8]),\n",
+ " ([9, 11], [1, 4, 5, 3, 7], [8, 2, 10]),\n",
+ " ([9, 11], [1, 4, 5, 3, 7], [8, 10, 2]),\n",
+ " ([9, 11], [1, 4, 5, 3, 7], [10, 2, 8]),\n",
+ " ([9, 11], [1, 4, 5, 3, 7], [10, 8, 2]),\n",
+ " ([9, 11], [1, 4, 5, 7, 3], [2, 8, 10]),\n",
+ " ([9, 11], [1, 4, 5, 7, 3], [2, 10, 8]),\n",
+ " ([9, 11], [1, 4, 5, 7, 3], [8, 2, 10]),\n",
+ " ([9, 11], [1, 4, 5, 7, 3], [8, 10, 2]),\n",
+ " ([9, 11], [1, 4, 5, 7, 3], [10, 2, 8]),\n",
+ " ([9, 11], [1, 4, 5, 7, 3], [10, 8, 2]),\n",
+ " ([9, 11], [1, 4, 5, 8, 2], [3, 7, 10]),\n",
+ " ([9, 11], [1, 4, 5, 8, 2], [3, 10, 7]),\n",
+ " ([9, 11], [1, 4, 5, 8, 2], [7, 3, 10]),\n",
+ " ([9, 11], [1, 4, 5, 8, 2], [7, 10, 3]),\n",
+ " ([9, 11], [1, 4, 5, 8, 2], [10, 3, 7]),\n",
+ " ([9, 11], [1, 4, 5, 8, 2], [10, 7, 3]),\n",
+ " ([9, 11], [1, 4, 5, 10], [2, 3, 7, 8]),\n",
+ " ([9, 11], [1, 4, 5, 10], [2, 3, 8, 7]),\n",
+ " ([9, 11], [1, 4, 5, 10], [2, 7, 3, 8]),\n",
+ " ([9, 11], [1, 4, 5, 10], [2, 7, 8, 3]),\n",
+ " ([9, 11], [1, 4, 5, 10], [2, 8, 3, 7]),\n",
+ " ([9, 11], [1, 4, 5, 10], [2, 8, 7, 3]),\n",
+ " ([9, 11], [1, 4, 5, 10], [3, 2, 7, 8]),\n",
+ " ([9, 11], [1, 4, 5, 10], [3, 2, 8, 7]),\n",
+ " ([9, 11], [1, 4, 5, 10], [3, 7, 2, 8]),\n",
+ " ([9, 11], [1, 4, 5, 10], [3, 7, 8, 2]),\n",
+ " ([9, 11], [1, 4, 5, 10], [3, 8, 2, 7]),\n",
+ " ([9, 11], [1, 4, 5, 10], [3, 8, 7, 2]),\n",
+ " ([9, 11], [1, 4, 5, 10], [7, 2, 3, 8]),\n",
+ " ([9, 11], [1, 4, 5, 10], [7, 2, 8, 3]),\n",
+ " ([9, 11], [1, 4, 5, 10], [7, 3, 2, 8]),\n",
+ " ([9, 11], [1, 4, 5, 10], [7, 3, 8, 2]),\n",
+ " ([9, 11], [1, 4, 5, 10], [7, 8, 2, 3]),\n",
+ " ([9, 11], [1, 4, 5, 10], [7, 8, 3, 2]),\n",
+ " ([9, 11], [1, 4, 5, 10], [8, 2, 3, 7]),\n",
+ " ([9, 11], [1, 4, 5, 10], [8, 2, 7, 3]),\n",
+ " ([9, 11], [1, 4, 5, 10], [8, 3, 2, 7]),\n",
+ " ([9, 11], [1, 4, 5, 10], [8, 3, 7, 2]),\n",
+ " ([9, 11], [1, 4, 5, 10], [8, 7, 2, 3]),\n",
+ " ([9, 11], [1, 4, 5, 10], [8, 7, 3, 2]),\n",
+ " ([9, 11], [1, 4, 7, 3, 5], [2, 8, 10]),\n",
+ " ([9, 11], [1, 4, 7, 3, 5], [2, 10, 8]),\n",
+ " ([9, 11], [1, 4, 7, 3, 5], [8, 2, 10]),\n",
+ " ([9, 11], [1, 4, 7, 3, 5], [8, 10, 2]),\n",
+ " ([9, 11], [1, 4, 7, 3, 5], [10, 2, 8]),\n",
+ " ([9, 11], [1, 4, 7, 3, 5], [10, 8, 2]),\n",
+ " ([9, 11], [1, 4, 7, 5, 3], [2, 8, 10]),\n",
+ " ([9, 11], [1, 4, 7, 5, 3], [2, 10, 8]),\n",
+ " ([9, 11], [1, 4, 7, 5, 3], [8, 2, 10]),\n",
+ " ([9, 11], [1, 4, 7, 5, 3], [8, 10, 2]),\n",
+ " ([9, 11], [1, 4, 7, 5, 3], [10, 2, 8]),\n",
+ " ([9, 11], [1, 4, 7, 5, 3], [10, 8, 2]),\n",
+ " ([9, 11], [1, 4, 7, 8], [2, 3, 5, 10]),\n",
+ " ([9, 11], [1, 4, 7, 8], [2, 3, 10, 5]),\n",
+ " ([9, 11], [1, 4, 7, 8], [2, 5, 3, 10]),\n",
+ " ([9, 11], [1, 4, 7, 8], [2, 5, 10, 3]),\n",
+ " ([9, 11], [1, 4, 7, 8], [2, 10, 3, 5]),\n",
+ " ([9, 11], [1, 4, 7, 8], [2, 10, 5, 3]),\n",
+ " ([9, 11], [1, 4, 7, 8], [3, 2, 5, 10]),\n",
+ " ([9, 11], [1, 4, 7, 8], [3, 2, 10, 5]),\n",
+ " ([9, 11], [1, 4, 7, 8], [3, 5, 2, 10]),\n",
+ " ([9, 11], [1, 4, 7, 8], [3, 5, 10, 2]),\n",
+ " ([9, 11], [1, 4, 7, 8], [3, 10, 2, 5]),\n",
+ " ([9, 11], [1, 4, 7, 8], [3, 10, 5, 2]),\n",
+ " ([9, 11], [1, 4, 7, 8], [5, 2, 3, 10]),\n",
+ " ([9, 11], [1, 4, 7, 8], [5, 2, 10, 3]),\n",
+ " ([9, 11], [1, 4, 7, 8], [5, 3, 2, 10]),\n",
+ " ([9, 11], [1, 4, 7, 8], [5, 3, 10, 2]),\n",
+ " ([9, 11], [1, 4, 7, 8], [5, 10, 2, 3]),\n",
+ " ([9, 11], [1, 4, 7, 8], [5, 10, 3, 2]),\n",
+ " ([9, 11], [1, 4, 7, 8], [10, 2, 3, 5]),\n",
+ " ([9, 11], [1, 4, 7, 8], [10, 2, 5, 3]),\n",
+ " ([9, 11], [1, 4, 7, 8], [10, 3, 2, 5]),\n",
+ " ([9, 11], [1, 4, 7, 8], [10, 3, 5, 2]),\n",
+ " ([9, 11], [1, 4, 7, 8], [10, 5, 2, 3]),\n",
+ " ([9, 11], [1, 4, 7, 8], [10, 5, 3, 2]),\n",
+ " ([9, 11], [1, 4, 8, 2, 5], [3, 7, 10]),\n",
+ " ([9, 11], [1, 4, 8, 2, 5], [3, 10, 7]),\n",
+ " ([9, 11], [1, 4, 8, 2, 5], [7, 3, 10]),\n",
+ " ([9, 11], [1, 4, 8, 2, 5], [7, 10, 3]),\n",
+ " ([9, 11], [1, 4, 8, 2, 5], [10, 3, 7]),\n",
+ " ([9, 11], [1, 4, 8, 2, 5], [10, 7, 3]),\n",
+ " ([9, 11], [1, 4, 8, 5, 2], [3, 7, 10]),\n",
+ " ([9, 11], [1, 4, 8, 5, 2], [3, 10, 7]),\n",
+ " ([9, 11], [1, 4, 8, 5, 2], [7, 3, 10]),\n",
+ " ([9, 11], [1, 4, 8, 5, 2], [7, 10, 3]),\n",
+ " ([9, 11], [1, 4, 8, 5, 2], [10, 3, 7]),\n",
+ " ([9, 11], [1, 4, 8, 5, 2], [10, 7, 3]),\n",
+ " ([9, 11], [1, 4, 8, 7], [2, 3, 5, 10]),\n",
+ " ([9, 11], [1, 4, 8, 7], [2, 3, 10, 5]),\n",
+ " ([9, 11], [1, 4, 8, 7], [2, 5, 3, 10]),\n",
+ " ([9, 11], [1, 4, 8, 7], [2, 5, 10, 3]),\n",
+ " ([9, 11], [1, 4, 8, 7], [2, 10, 3, 5]),\n",
+ " ([9, 11], [1, 4, 8, 7], [2, 10, 5, 3]),\n",
+ " ([9, 11], [1, 4, 8, 7], [3, 2, 5, 10]),\n",
+ " ([9, 11], [1, 4, 8, 7], [3, 2, 10, 5]),\n",
+ " ([9, 11], [1, 4, 8, 7], [3, 5, 2, 10]),\n",
+ " ([9, 11], [1, 4, 8, 7], [3, 5, 10, 2]),\n",
+ " ([9, 11], [1, 4, 8, 7], [3, 10, 2, 5]),\n",
+ " ([9, 11], [1, 4, 8, 7], [3, 10, 5, 2]),\n",
+ " ([9, 11], [1, 4, 8, 7], [5, 2, 3, 10]),\n",
+ " ([9, 11], [1, 4, 8, 7], [5, 2, 10, 3]),\n",
+ " ([9, 11], [1, 4, 8, 7], [5, 3, 2, 10]),\n",
+ " ([9, 11], [1, 4, 8, 7], [5, 3, 10, 2]),\n",
+ " ([9, 11], [1, 4, 8, 7], [5, 10, 2, 3]),\n",
+ " ([9, 11], [1, 4, 8, 7], [5, 10, 3, 2]),\n",
+ " ([9, 11], [1, 4, 8, 7], [10, 2, 3, 5]),\n",
+ " ([9, 11], [1, 4, 8, 7], [10, 2, 5, 3]),\n",
+ " ([9, 11], [1, 4, 8, 7], [10, 3, 2, 5]),\n",
+ " ([9, 11], [1, 4, 8, 7], [10, 3, 5, 2]),\n",
+ " ([9, 11], [1, 4, 8, 7], [10, 5, 2, 3]),\n",
+ " ([9, 11], [1, 4, 8, 7], [10, 5, 3, 2]),\n",
+ " ([9, 11], [1, 4, 10, 2, 3], [5, 7, 8]),\n",
+ " ([9, 11], [1, 4, 10, 2, 3], [5, 8, 7]),\n",
+ " ([9, 11], [1, 4, 10, 2, 3], [7, 5, 8]),\n",
+ " ([9, 11], [1, 4, 10, 2, 3], [7, 8, 5]),\n",
+ " ([9, 11], [1, 4, 10, 2, 3], [8, 5, 7]),\n",
+ " ([9, 11], [1, 4, 10, 2, 3], [8, 7, 5]),\n",
+ " ([9, 11], [1, 4, 10, 3, 2], [5, 7, 8]),\n",
+ " ([9, 11], [1, 4, 10, 3, 2], [5, 8, 7]),\n",
+ " ([9, 11], [1, 4, 10, 3, 2], [7, 5, 8]),\n",
+ " ([9, 11], [1, 4, 10, 3, 2], [7, 8, 5]),\n",
+ " ([9, 11], [1, 4, 10, 3, 2], [8, 5, 7]),\n",
+ " ([9, 11], [1, 4, 10, 3, 2], [8, 7, 5]),\n",
+ " ([9, 11], [1, 4, 10, 5], [2, 3, 7, 8]),\n",
+ " ([9, 11], [1, 4, 10, 5], [2, 3, 8, 7]),\n",
+ " ([9, 11], [1, 4, 10, 5], [2, 7, 3, 8]),\n",
+ " ([9, 11], [1, 4, 10, 5], [2, 7, 8, 3]),\n",
+ " ([9, 11], [1, 4, 10, 5], [2, 8, 3, 7]),\n",
+ " ([9, 11], [1, 4, 10, 5], [2, 8, 7, 3]),\n",
+ " ([9, 11], [1, 4, 10, 5], [3, 2, 7, 8]),\n",
+ " ([9, 11], [1, 4, 10, 5], [3, 2, 8, 7]),\n",
+ " ([9, 11], [1, 4, 10, 5], [3, 7, 2, 8]),\n",
+ " ([9, 11], [1, 4, 10, 5], [3, 7, 8, 2]),\n",
+ " ([9, 11], [1, 4, 10, 5], [3, 8, 2, 7]),\n",
+ " ([9, 11], [1, 4, 10, 5], [3, 8, 7, 2]),\n",
+ " ([9, 11], [1, 4, 10, 5], [7, 2, 3, 8]),\n",
+ " ([9, 11], [1, 4, 10, 5], [7, 2, 8, 3]),\n",
+ " ([9, 11], [1, 4, 10, 5], [7, 3, 2, 8]),\n",
+ " ([9, 11], [1, 4, 10, 5], [7, 3, 8, 2]),\n",
+ " ([9, 11], [1, 4, 10, 5], [7, 8, 2, 3]),\n",
+ " ([9, 11], [1, 4, 10, 5], [7, 8, 3, 2]),\n",
+ " ([9, 11], [1, 4, 10, 5], [8, 2, 3, 7]),\n",
+ " ([9, 11], [1, 4, 10, 5], [8, 2, 7, 3]),\n",
+ " ([9, 11], [1, 4, 10, 5], [8, 3, 2, 7]),\n",
+ " ([9, 11], [1, 4, 10, 5], [8, 3, 7, 2]),\n",
+ " ([9, 11], [1, 4, 10, 5], [8, 7, 2, 3]),\n",
+ " ([9, 11], [1, 4, 10, 5], [8, 7, 3, 2]),\n",
+ " ([9, 11], [1, 5, 2, 4, 8], [3, 7, 10]),\n",
+ " ([9, 11], [1, 5, 2, 4, 8], [3, 10, 7]),\n",
+ " ([9, 11], [1, 5, 2, 4, 8], [7, 3, 10]),\n",
+ " ([9, 11], [1, 5, 2, 4, 8], [7, 10, 3]),\n",
+ " ([9, 11], [1, 5, 2, 4, 8], [10, 3, 7]),\n",
+ " ([9, 11], [1, 5, 2, 4, 8], [10, 7, 3]),\n",
+ " ([9, 11], [1, 5, 2, 8, 4], [3, 7, 10]),\n",
+ " ([9, 11], [1, 5, 2, 8, 4], [3, 10, 7]),\n",
+ " ([9, 11], [1, 5, 2, 8, 4], [7, 3, 10]),\n",
+ " ([9, 11], [1, 5, 2, 8, 4], [7, 10, 3]),\n",
+ " ([9, 11], [1, 5, 2, 8, 4], [10, 3, 7]),\n",
+ " ([9, 11], [1, 5, 2, 8, 4], [10, 7, 3]),\n",
+ " ([9, 11], [1, 5, 3, 4, 7], [2, 8, 10]),\n",
+ " ([9, 11], [1, 5, 3, 4, 7], [2, 10, 8]),\n",
+ " ([9, 11], [1, 5, 3, 4, 7], [8, 2, 10]),\n",
+ " ([9, 11], [1, 5, 3, 4, 7], [8, 10, 2]),\n",
+ " ([9, 11], [1, 5, 3, 4, 7], [10, 2, 8]),\n",
+ " ([9, 11], [1, 5, 3, 4, 7], [10, 8, 2]),\n",
+ " ([9, 11], [1, 5, 3, 7, 4], [2, 8, 10]),\n",
+ " ([9, 11], [1, 5, 3, 7, 4], [2, 10, 8]),\n",
+ " ([9, 11], [1, 5, 3, 7, 4], [8, 2, 10]),\n",
+ " ([9, 11], [1, 5, 3, 7, 4], [8, 10, 2]),\n",
+ " ([9, 11], [1, 5, 3, 7, 4], [10, 2, 8]),\n",
+ " ([9, 11], [1, 5, 3, 7, 4], [10, 8, 2]),\n",
+ " ([9, 11], [1, 5, 4, 2, 8], [3, 7, 10]),\n",
+ " ([9, 11], [1, 5, 4, 2, 8], [3, 10, 7]),\n",
+ " ([9, 11], [1, 5, 4, 2, 8], [7, 3, 10]),\n",
+ " ([9, 11], [1, 5, 4, 2, 8], [7, 10, 3]),\n",
+ " ([9, 11], [1, 5, 4, 2, 8], [10, 3, 7]),\n",
+ " ([9, 11], [1, 5, 4, 2, 8], [10, 7, 3]),\n",
+ " ([9, 11], [1, 5, 4, 3, 7], [2, 8, 10]),\n",
+ " ([9, 11], [1, 5, 4, 3, 7], [2, 10, 8]),\n",
+ " ([9, 11], [1, 5, 4, 3, 7], [8, 2, 10]),\n",
+ " ([9, 11], [1, 5, 4, 3, 7], [8, 10, 2]),\n",
+ " ([9, 11], [1, 5, 4, 3, 7], [10, 2, 8]),\n",
+ " ([9, 11], [1, 5, 4, 3, 7], [10, 8, 2]),\n",
+ " ([9, 11], [1, 5, 4, 7, 3], [2, 8, 10]),\n",
+ " ([9, 11], [1, 5, 4, 7, 3], [2, 10, 8]),\n",
+ " ([9, 11], [1, 5, 4, 7, 3], [8, 2, 10]),\n",
+ " ([9, 11], [1, 5, 4, 7, 3], [8, 10, 2]),\n",
+ " ([9, 11], [1, 5, 4, 7, 3], [10, 2, 8]),\n",
+ " ([9, 11], [1, 5, 4, 7, 3], [10, 8, 2]),\n",
+ " ([9, 11], [1, 5, 4, 8, 2], [3, 7, 10]),\n",
+ " ([9, 11], [1, 5, 4, 8, 2], [3, 10, 7]),\n",
+ " ([9, 11], [1, 5, 4, 8, 2], [7, 3, 10]),\n",
+ " ([9, 11], [1, 5, 4, 8, 2], [7, 10, 3]),\n",
+ " ([9, 11], [1, 5, 4, 8, 2], [10, 3, 7]),\n",
+ " ([9, 11], [1, 5, 4, 8, 2], [10, 7, 3]),\n",
+ " ([9, 11], [1, 5, 4, 10], [2, 3, 7, 8]),\n",
+ " ([9, 11], [1, 5, 4, 10], [2, 3, 8, 7]),\n",
+ " ([9, 11], [1, 5, 4, 10], [2, 7, 3, 8]),\n",
+ " ([9, 11], [1, 5, 4, 10], [2, 7, 8, 3]),\n",
+ " ([9, 11], [1, 5, 4, 10], [2, 8, 3, 7]),\n",
+ " ([9, 11], [1, 5, 4, 10], [2, 8, 7, 3]),\n",
+ " ([9, 11], [1, 5, 4, 10], [3, 2, 7, 8]),\n",
+ " ([9, 11], [1, 5, 4, 10], [3, 2, 8, 7]),\n",
+ " ([9, 11], [1, 5, 4, 10], [3, 7, 2, 8]),\n",
+ " ([9, 11], [1, 5, 4, 10], [3, 7, 8, 2]),\n",
+ " ([9, 11], [1, 5, 4, 10], [3, 8, 2, 7]),\n",
+ " ([9, 11], [1, 5, 4, 10], [3, 8, 7, 2]),\n",
+ " ([9, 11], [1, 5, 4, 10], [7, 2, 3, 8]),\n",
+ " ([9, 11], [1, 5, 4, 10], [7, 2, 8, 3]),\n",
+ " ([9, 11], [1, 5, 4, 10], [7, 3, 2, 8]),\n",
+ " ([9, 11], [1, 5, 4, 10], [7, 3, 8, 2]),\n",
+ " ([9, 11], [1, 5, 4, 10], [7, 8, 2, 3]),\n",
+ " ([9, 11], [1, 5, 4, 10], [7, 8, 3, 2]),\n",
+ " ([9, 11], [1, 5, 4, 10], [8, 2, 3, 7]),\n",
+ " ([9, 11], [1, 5, 4, 10], [8, 2, 7, 3]),\n",
+ " ([9, 11], [1, 5, 4, 10], [8, 3, 2, 7]),\n",
+ " ([9, 11], [1, 5, 4, 10], [8, 3, 7, 2]),\n",
+ " ([9, 11], [1, 5, 4, 10], [8, 7, 2, 3]),\n",
+ " ([9, 11], [1, 5, 4, 10], [8, 7, 3, 2]),\n",
+ " ([9, 11], [1, 5, 7, 3, 4], [2, 8, 10]),\n",
+ " ([9, 11], [1, 5, 7, 3, 4], [2, 10, 8]),\n",
+ " ([9, 11], [1, 5, 7, 3, 4], [8, 2, 10]),\n",
+ " ([9, 11], [1, 5, 7, 3, 4], [8, 10, 2]),\n",
+ " ([9, 11], [1, 5, 7, 3, 4], [10, 2, 8]),\n",
+ " ([9, 11], [1, 5, 7, 3, 4], [10, 8, 2]),\n",
+ " ([9, 11], [1, 5, 7, 4, 3], [2, 8, 10]),\n",
+ " ([9, 11], [1, 5, 7, 4, 3], [2, 10, 8]),\n",
+ " ([9, 11], [1, 5, 7, 4, 3], [8, 2, 10]),\n",
+ " ([9, 11], [1, 5, 7, 4, 3], [8, 10, 2]),\n",
+ " ([9, 11], [1, 5, 7, 4, 3], [10, 2, 8]),\n",
+ " ([9, 11], [1, 5, 7, 4, 3], [10, 8, 2]),\n",
+ " ([9, 11], [1, 5, 8, 2, 4], [3, 7, 10]),\n",
+ " ([9, 11], [1, 5, 8, 2, 4], [3, 10, 7]),\n",
+ " ([9, 11], [1, 5, 8, 2, 4], [7, 3, 10]),\n",
+ " ([9, 11], [1, 5, 8, 2, 4], [7, 10, 3]),\n",
+ " ([9, 11], [1, 5, 8, 2, 4], [10, 3, 7]),\n",
+ " ([9, 11], [1, 5, 8, 2, 4], [10, 7, 3]),\n",
+ " ([9, 11], [1, 5, 8, 4, 2], [3, 7, 10]),\n",
+ " ([9, 11], [1, 5, 8, 4, 2], [3, 10, 7]),\n",
+ " ([9, 11], [1, 5, 8, 4, 2], [7, 3, 10]),\n",
+ " ([9, 11], [1, 5, 8, 4, 2], [7, 10, 3]),\n",
+ " ([9, 11], [1, 5, 8, 4, 2], [10, 3, 7]),\n",
+ " ([9, 11], [1, 5, 8, 4, 2], [10, 7, 3]),\n",
+ " ([9, 11], [1, 5, 10, 4], [2, 3, 7, 8]),\n",
+ " ([9, 11], [1, 5, 10, 4], [2, 3, 8, 7]),\n",
+ " ([9, 11], [1, 5, 10, 4], [2, 7, 3, 8]),\n",
+ " ([9, 11], [1, 5, 10, 4], [2, 7, 8, 3]),\n",
+ " ([9, 11], [1, 5, 10, 4], [2, 8, 3, 7]),\n",
+ " ([9, 11], [1, 5, 10, 4], [2, 8, 7, 3]),\n",
+ " ([9, 11], [1, 5, 10, 4], [3, 2, 7, 8]),\n",
+ " ([9, 11], [1, 5, 10, 4], [3, 2, 8, 7]),\n",
+ " ([9, 11], [1, 5, 10, 4], [3, 7, 2, 8]),\n",
+ " ([9, 11], [1, 5, 10, 4], [3, 7, 8, 2]),\n",
+ " ([9, 11], [1, 5, 10, 4], [3, 8, 2, 7]),\n",
+ " ([9, 11], [1, 5, 10, 4], [3, 8, 7, 2]),\n",
+ " ([9, 11], [1, 5, 10, 4], [7, 2, 3, 8]),\n",
+ " ([9, 11], [1, 5, 10, 4], [7, 2, 8, 3]),\n",
+ " ([9, 11], [1, 5, 10, 4], [7, 3, 2, 8]),\n",
+ " ([9, 11], [1, 5, 10, 4], [7, 3, 8, 2]),\n",
+ " ([9, 11], [1, 5, 10, 4], [7, 8, 2, 3]),\n",
+ " ([9, 11], [1, 5, 10, 4], [7, 8, 3, 2]),\n",
+ " ([9, 11], [1, 5, 10, 4], [8, 2, 3, 7]),\n",
+ " ([9, 11], [1, 5, 10, 4], [8, 2, 7, 3]),\n",
+ " ([9, 11], [1, 5, 10, 4], [8, 3, 2, 7]),\n",
+ " ([9, 11], [1, 5, 10, 4], [8, 3, 7, 2]),\n",
+ " ([9, 11], [1, 5, 10, 4], [8, 7, 2, 3]),\n",
+ " ([9, 11], [1, 5, 10, 4], [8, 7, 3, 2]),\n",
+ " ([9, 11], [1, 7, 2, 10], [3, 4, 5, 8]),\n",
+ " ([9, 11], [1, 7, 2, 10], [3, 4, 8, 5]),\n",
+ " ([9, 11], [1, 7, 2, 10], [3, 5, 4, 8]),\n",
+ " ([9, 11], [1, 7, 2, 10], [3, 5, 8, 4]),\n",
+ " ([9, 11], [1, 7, 2, 10], [3, 8, 4, 5]),\n",
+ " ([9, 11], [1, 7, 2, 10], [3, 8, 5, 4]),\n",
+ " ([9, 11], [1, 7, 2, 10], [4, 3, 5, 8]),\n",
+ " ([9, 11], [1, 7, 2, 10], [4, 3, 8, 5]),\n",
+ " ([9, 11], [1, 7, 2, 10], [4, 5, 3, 8]),\n",
+ " ([9, 11], [1, 7, 2, 10], [4, 5, 8, 3]),\n",
+ " ([9, 11], [1, 7, 2, 10], [4, 8, 3, 5]),\n",
+ " ([9, 11], [1, 7, 2, 10], [4, 8, 5, 3]),\n",
+ " ([9, 11], [1, 7, 2, 10], [5, 3, 4, 8]),\n",
+ " ([9, 11], [1, 7, 2, 10], [5, 3, 8, 4]),\n",
+ " ([9, 11], [1, 7, 2, 10], [5, 4, 3, 8]),\n",
+ " ([9, 11], [1, 7, 2, 10], [5, 4, 8, 3]),\n",
+ " ([9, 11], [1, 7, 2, 10], [5, 8, 3, 4]),\n",
+ " ([9, 11], [1, 7, 2, 10], [5, 8, 4, 3]),\n",
+ " ([9, 11], [1, 7, 2, 10], [8, 3, 4, 5]),\n",
+ " ([9, 11], [1, 7, 2, 10], [8, 3, 5, 4]),\n",
+ " ([9, 11], [1, 7, 2, 10], [8, 4, 3, 5]),\n",
+ " ([9, 11], [1, 7, 2, 10], [8, 4, 5, 3]),\n",
+ " ([9, 11], [1, 7, 2, 10], [8, 5, 3, 4]),\n",
+ " ([9, 11], [1, 7, 2, 10], [8, 5, 4, 3]),\n",
+ " ([9, 11], [1, 7, 3, 4, 5], [2, 8, 10]),\n",
+ " ([9, 11], [1, 7, 3, 4, 5], [2, 10, 8]),\n",
+ " ([9, 11], [1, 7, 3, 4, 5], [8, 2, 10]),\n",
+ " ([9, 11], [1, 7, 3, 4, 5], [8, 10, 2]),\n",
+ " ([9, 11], [1, 7, 3, 4, 5], [10, 2, 8]),\n",
+ " ([9, 11], [1, 7, 3, 4, 5], [10, 8, 2]),\n",
+ " ([9, 11], [1, 7, 3, 5, 4], [2, 8, 10]),\n",
+ " ([9, 11], [1, 7, 3, 5, 4], [2, 10, 8]),\n",
+ " ([9, 11], [1, 7, 3, 5, 4], [8, 2, 10]),\n",
+ " ([9, 11], [1, 7, 3, 5, 4], [8, 10, 2]),\n",
+ " ([9, 11], [1, 7, 3, 5, 4], [10, 2, 8]),\n",
+ " ([9, 11], [1, 7, 3, 5, 4], [10, 8, 2]),\n",
+ " ([9, 11], [1, 7, 4, 3, 5], [2, 8, 10]),\n",
+ " ([9, 11], [1, 7, 4, 3, 5], [2, 10, 8]),\n",
+ " ([9, 11], [1, 7, 4, 3, 5], [8, 2, 10]),\n",
+ " ([9, 11], [1, 7, 4, 3, 5], [8, 10, 2]),\n",
+ " ([9, 11], [1, 7, 4, 3, 5], [10, 2, 8]),\n",
+ " ([9, 11], [1, 7, 4, 3, 5], [10, 8, 2]),\n",
+ " ([9, 11], [1, 7, 4, 5, 3], [2, 8, 10]),\n",
+ " ([9, 11], [1, 7, 4, 5, 3], [2, 10, 8]),\n",
+ " ([9, 11], [1, 7, 4, 5, 3], [8, 2, 10]),\n",
+ " ([9, 11], [1, 7, 4, 5, 3], [8, 10, 2]),\n",
+ " ([9, 11], [1, 7, 4, 5, 3], [10, 2, 8]),\n",
+ " ([9, 11], [1, 7, 4, 5, 3], [10, 8, 2]),\n",
+ " ([9, 11], [1, 7, 4, 8], [2, 3, 5, 10]),\n",
+ " ([9, 11], [1, 7, 4, 8], [2, 3, 10, 5]),\n",
+ " ([9, 11], [1, 7, 4, 8], [2, 5, 3, 10]),\n",
+ " ([9, 11], [1, 7, 4, 8], [2, 5, 10, 3]),\n",
+ " ([9, 11], [1, 7, 4, 8], [2, 10, 3, 5]),\n",
+ " ([9, 11], [1, 7, 4, 8], [2, 10, 5, 3]),\n",
+ " ([9, 11], [1, 7, 4, 8], [3, 2, 5, 10]),\n",
+ " ([9, 11], [1, 7, 4, 8], [3, 2, 10, 5]),\n",
+ " ([9, 11], [1, 7, 4, 8], [3, 5, 2, 10]),\n",
+ " ([9, 11], [1, 7, 4, 8], [3, 5, 10, 2]),\n",
+ " ([9, 11], [1, 7, 4, 8], [3, 10, 2, 5]),\n",
+ " ([9, 11], [1, 7, 4, 8], [3, 10, 5, 2]),\n",
+ " ([9, 11], [1, 7, 4, 8], [5, 2, 3, 10]),\n",
+ " ([9, 11], [1, 7, 4, 8], [5, 2, 10, 3]),\n",
+ " ([9, 11], [1, 7, 4, 8], [5, 3, 2, 10]),\n",
+ " ([9, 11], [1, 7, 4, 8], [5, 3, 10, 2]),\n",
+ " ([9, 11], [1, 7, 4, 8], [5, 10, 2, 3]),\n",
+ " ([9, 11], [1, 7, 4, 8], [5, 10, 3, 2]),\n",
+ " ([9, 11], [1, 7, 4, 8], [10, 2, 3, 5]),\n",
+ " ([9, 11], [1, 7, 4, 8], [10, 2, 5, 3]),\n",
+ " ([9, 11], [1, 7, 4, 8], [10, 3, 2, 5]),\n",
+ " ([9, 11], [1, 7, 4, 8], [10, 3, 5, 2]),\n",
+ " ([9, 11], [1, 7, 4, 8], [10, 5, 2, 3]),\n",
+ " ([9, 11], [1, 7, 4, 8], [10, 5, 3, 2]),\n",
+ " ([9, 11], [1, 7, 5, 3, 4], [2, 8, 10]),\n",
+ " ([9, 11], [1, 7, 5, 3, 4], [2, 10, 8]),\n",
+ " ([9, 11], [1, 7, 5, 3, 4], [8, 2, 10]),\n",
+ " ([9, 11], [1, 7, 5, 3, 4], [8, 10, 2]),\n",
+ " ([9, 11], [1, 7, 5, 3, 4], [10, 2, 8]),\n",
+ " ([9, 11], [1, 7, 5, 3, 4], [10, 8, 2]),\n",
+ " ([9, 11], [1, 7, 5, 4, 3], [2, 8, 10]),\n",
+ " ([9, 11], [1, 7, 5, 4, 3], [2, 10, 8]),\n",
+ " ([9, 11], [1, 7, 5, 4, 3], [8, 2, 10]),\n",
+ " ([9, 11], [1, 7, 5, 4, 3], [8, 10, 2]),\n",
+ " ([9, 11], [1, 7, 5, 4, 3], [10, 2, 8]),\n",
+ " ([9, 11], [1, 7, 5, 4, 3], [10, 8, 2]),\n",
+ " ([9, 11], [1, 7, 8, 4], [2, 3, 5, 10]),\n",
+ " ([9, 11], [1, 7, 8, 4], [2, 3, 10, 5]),\n",
+ " ([9, 11], [1, 7, 8, 4], [2, 5, 3, 10]),\n",
+ " ([9, 11], [1, 7, 8, 4], [2, 5, 10, 3]),\n",
+ " ([9, 11], [1, 7, 8, 4], [2, 10, 3, 5]),\n",
+ " ([9, 11], [1, 7, 8, 4], [2, 10, 5, 3]),\n",
+ " ([9, 11], [1, 7, 8, 4], [3, 2, 5, 10]),\n",
+ " ([9, 11], [1, 7, 8, 4], [3, 2, 10, 5]),\n",
+ " ([9, 11], [1, 7, 8, 4], [3, 5, 2, 10]),\n",
+ " ([9, 11], [1, 7, 8, 4], [3, 5, 10, 2]),\n",
+ " ([9, 11], [1, 7, 8, 4], [3, 10, 2, 5]),\n",
+ " ([9, 11], [1, 7, 8, 4], [3, 10, 5, 2]),\n",
+ " ([9, 11], [1, 7, 8, 4], [5, 2, 3, 10]),\n",
+ " ([9, 11], [1, 7, 8, 4], [5, 2, 10, 3]),\n",
+ " ([9, 11], [1, 7, 8, 4], [5, 3, 2, 10]),\n",
+ " ([9, 11], [1, 7, 8, 4], [5, 3, 10, 2]),\n",
+ " ([9, 11], [1, 7, 8, 4], [5, 10, 2, 3]),\n",
+ " ([9, 11], [1, 7, 8, 4], [5, 10, 3, 2]),\n",
+ " ([9, 11], [1, 7, 8, 4], [10, 2, 3, 5]),\n",
+ " ([9, 11], [1, 7, 8, 4], [10, 2, 5, 3]),\n",
+ " ([9, 11], [1, 7, 8, 4], [10, 3, 2, 5]),\n",
+ " ([9, 11], [1, 7, 8, 4], [10, 3, 5, 2]),\n",
+ " ([9, 11], [1, 7, 8, 4], [10, 5, 2, 3]),\n",
+ " ([9, 11], [1, 7, 8, 4], [10, 5, 3, 2]),\n",
+ " ([9, 11], [1, 7, 10, 2], [3, 4, 5, 8]),\n",
+ " ([9, 11], [1, 7, 10, 2], [3, 4, 8, 5]),\n",
+ " ([9, 11], [1, 7, 10, 2], [3, 5, 4, 8]),\n",
+ " ([9, 11], [1, 7, 10, 2], [3, 5, 8, 4]),\n",
+ " ([9, 11], [1, 7, 10, 2], [3, 8, 4, 5]),\n",
+ " ([9, 11], [1, 7, 10, 2], [3, 8, 5, 4]),\n",
+ " ([9, 11], [1, 7, 10, 2], [4, 3, 5, 8]),\n",
+ " ([9, 11], [1, 7, 10, 2], [4, 3, 8, 5]),\n",
+ " ([9, 11], [1, 7, 10, 2], [4, 5, 3, 8]),\n",
+ " ([9, 11], [1, 7, 10, 2], [4, 5, 8, 3]),\n",
+ " ([9, 11], [1, 7, 10, 2], [4, 8, 3, 5]),\n",
+ " ([9, 11], [1, 7, 10, 2], [4, 8, 5, 3]),\n",
+ " ([9, 11], [1, 7, 10, 2], [5, 3, 4, 8]),\n",
+ " ([9, 11], [1, 7, 10, 2], [5, 3, 8, 4]),\n",
+ " ([9, 11], [1, 7, 10, 2], [5, 4, 3, 8]),\n",
+ " ([9, 11], [1, 7, 10, 2], [5, 4, 8, 3]),\n",
+ " ([9, 11], [1, 7, 10, 2], [5, 8, 3, 4]),\n",
+ " ([9, 11], [1, 7, 10, 2], [5, 8, 4, 3]),\n",
+ " ([9, 11], [1, 7, 10, 2], [8, 3, 4, 5]),\n",
+ " ([9, 11], [1, 7, 10, 2], [8, 3, 5, 4]),\n",
+ " ([9, 11], [1, 7, 10, 2], [8, 4, 3, 5]),\n",
+ " ([9, 11], [1, 7, 10, 2], [8, 4, 5, 3]),\n",
+ " ([9, 11], [1, 7, 10, 2], [8, 5, 3, 4]),\n",
+ " ([9, 11], [1, 7, 10, 2], [8, 5, 4, 3]),\n",
+ " ([9, 11], [1, 8, 2, 4, 5], [3, 7, 10]),\n",
+ " ([9, 11], [1, 8, 2, 4, 5], [3, 10, 7]),\n",
+ " ([9, 11], [1, 8, 2, 4, 5], [7, 3, 10]),\n",
+ " ([9, 11], [1, 8, 2, 4, 5], [7, 10, 3]),\n",
+ " ([9, 11], [1, 8, 2, 4, 5], [10, 3, 7]),\n",
+ " ([9, 11], [1, 8, 2, 4, 5], [10, 7, 3]),\n",
+ " ([9, 11], [1, 8, 2, 5, 4], [3, 7, 10]),\n",
+ " ([9, 11], [1, 8, 2, 5, 4], [3, 10, 7]),\n",
+ " ([9, 11], [1, 8, 2, 5, 4], [7, 3, 10]),\n",
+ " ([9, 11], [1, 8, 2, 5, 4], [7, 10, 3]),\n",
+ " ([9, 11], [1, 8, 2, 5, 4], [10, 3, 7]),\n",
+ " ([9, 11], [1, 8, 2, 5, 4], [10, 7, 3]),\n",
+ " ([9, 11], [1, 8, 4, 2, 5], [3, 7, 10]),\n",
+ " ([9, 11], [1, 8, 4, 2, 5], [3, 10, 7]),\n",
+ " ([9, 11], [1, 8, 4, 2, 5], [7, 3, 10]),\n",
+ " ([9, 11], [1, 8, 4, 2, 5], [7, 10, 3]),\n",
+ " ([9, 11], [1, 8, 4, 2, 5], [10, 3, 7]),\n",
+ " ([9, 11], [1, 8, 4, 2, 5], [10, 7, 3]),\n",
+ " ([9, 11], [1, 8, 4, 5, 2], [3, 7, 10]),\n",
+ " ([9, 11], [1, 8, 4, 5, 2], [3, 10, 7]),\n",
+ " ([9, 11], [1, 8, 4, 5, 2], [7, 3, 10]),\n",
+ " ([9, 11], [1, 8, 4, 5, 2], [7, 10, 3]),\n",
+ " ([9, 11], [1, 8, 4, 5, 2], [10, 3, 7]),\n",
+ " ([9, 11], [1, 8, 4, 5, 2], [10, 7, 3]),\n",
+ " ([9, 11], [1, 8, 4, 7], [2, 3, 5, 10]),\n",
+ " ([9, 11], [1, 8, 4, 7], [2, 3, 10, 5]),\n",
+ " ([9, 11], [1, 8, 4, 7], [2, 5, 3, 10]),\n",
+ " ([9, 11], [1, 8, 4, 7], [2, 5, 10, 3]),\n",
+ " ([9, 11], [1, 8, 4, 7], [2, 10, 3, 5]),\n",
+ " ([9, 11], [1, 8, 4, 7], [2, 10, 5, 3]),\n",
+ " ([9, 11], [1, 8, 4, 7], [3, 2, 5, 10]),\n",
+ " ([9, 11], [1, 8, 4, 7], [3, 2, 10, 5]),\n",
+ " ([9, 11], [1, 8, 4, 7], [3, 5, 2, 10]),\n",
+ " ([9, 11], [1, 8, 4, 7], [3, 5, 10, 2]),\n",
+ " ([9, 11], [1, 8, 4, 7], [3, 10, 2, 5]),\n",
+ " ([9, 11], [1, 8, 4, 7], [3, 10, 5, 2]),\n",
+ " ([9, 11], [1, 8, 4, 7], [5, 2, 3, 10]),\n",
+ " ([9, 11], [1, 8, 4, 7], [5, 2, 10, 3]),\n",
+ " ([9, 11], [1, 8, 4, 7], [5, 3, 2, 10]),\n",
+ " ([9, 11], [1, 8, 4, 7], [5, 3, 10, 2]),\n",
+ " ([9, 11], [1, 8, 4, 7], [5, 10, 2, 3]),\n",
+ " ([9, 11], [1, 8, 4, 7], [5, 10, 3, 2]),\n",
+ " ([9, 11], [1, 8, 4, 7], [10, 2, 3, 5]),\n",
+ " ([9, 11], [1, 8, 4, 7], [10, 2, 5, 3]),\n",
+ " ([9, 11], [1, 8, 4, 7], [10, 3, 2, 5]),\n",
+ " ([9, 11], [1, 8, 4, 7], [10, 3, 5, 2]),\n",
+ " ([9, 11], [1, 8, 4, 7], [10, 5, 2, 3]),\n",
+ " ([9, 11], [1, 8, 4, 7], [10, 5, 3, 2]),\n",
+ " ([9, 11], [1, 8, 5, 2, 4], [3, 7, 10]),\n",
+ " ([9, 11], [1, 8, 5, 2, 4], [3, 10, 7]),\n",
+ " ([9, 11], [1, 8, 5, 2, 4], [7, 3, 10]),\n",
+ " ([9, 11], [1, 8, 5, 2, 4], [7, 10, 3]),\n",
+ " ([9, 11], [1, 8, 5, 2, 4], [10, 3, 7]),\n",
+ " ([9, 11], [1, 8, 5, 2, 4], [10, 7, 3]),\n",
+ " ([9, 11], [1, 8, 5, 4, 2], [3, 7, 10]),\n",
+ " ([9, 11], [1, 8, 5, 4, 2], [3, 10, 7]),\n",
+ " ([9, 11], [1, 8, 5, 4, 2], [7, 3, 10]),\n",
+ " ([9, 11], [1, 8, 5, 4, 2], [7, 10, 3]),\n",
+ " ([9, 11], [1, 8, 5, 4, 2], [10, 3, 7]),\n",
+ " ([9, 11], [1, 8, 5, 4, 2], [10, 7, 3]),\n",
+ " ([9, 11], [1, 8, 7, 4], [2, 3, 5, 10]),\n",
+ " ([9, 11], [1, 8, 7, 4], [2, 3, 10, 5]),\n",
+ " ([9, 11], [1, 8, 7, 4], [2, 5, 3, 10]),\n",
+ " ([9, 11], [1, 8, 7, 4], [2, 5, 10, 3]),\n",
+ " ([9, 11], [1, 8, 7, 4], [2, 10, 3, 5]),\n",
+ " ([9, 11], [1, 8, 7, 4], [2, 10, 5, 3]),\n",
+ " ([9, 11], [1, 8, 7, 4], [3, 2, 5, 10]),\n",
+ " ([9, 11], [1, 8, 7, 4], [3, 2, 10, 5]),\n",
+ " ([9, 11], [1, 8, 7, 4], [3, 5, 2, 10]),\n",
+ " ([9, 11], [1, 8, 7, 4], [3, 5, 10, 2]),\n",
+ " ([9, 11], [1, 8, 7, 4], [3, 10, 2, 5]),\n",
+ " ([9, 11], [1, 8, 7, 4], [3, 10, 5, 2]),\n",
+ " ([9, 11], [1, 8, 7, 4], [5, 2, 3, 10]),\n",
+ " ([9, 11], [1, 8, 7, 4], [5, 2, 10, 3]),\n",
+ " ([9, 11], [1, 8, 7, 4], [5, 3, 2, 10]),\n",
+ " ([9, 11], [1, 8, 7, 4], [5, 3, 10, 2]),\n",
+ " ([9, 11], [1, 8, 7, 4], [5, 10, 2, 3]),\n",
+ " ([9, 11], [1, 8, 7, 4], [5, 10, 3, 2]),\n",
+ " ([9, 11], [1, 8, 7, 4], [10, 2, 3, 5]),\n",
+ " ([9, 11], [1, 8, 7, 4], [10, 2, 5, 3]),\n",
+ " ([9, 11], [1, 8, 7, 4], [10, 3, 2, 5]),\n",
+ " ([9, 11], [1, 8, 7, 4], [10, 3, 5, 2]),\n",
+ " ([9, 11], [1, 8, 7, 4], [10, 5, 2, 3]),\n",
+ " ([9, 11], [1, 8, 7, 4], [10, 5, 3, 2]),\n",
+ " ([9, 11], [1, 10, 2, 3, 4], [5, 7, 8]),\n",
+ " ([9, 11], [1, 10, 2, 3, 4], [5, 8, 7]),\n",
+ " ([9, 11], [1, 10, 2, 3, 4], [7, 5, 8]),\n",
+ " ([9, 11], [1, 10, 2, 3, 4], [7, 8, 5]),\n",
+ " ([9, 11], [1, 10, 2, 3, 4], [8, 5, 7]),\n",
+ " ([9, 11], [1, 10, 2, 3, 4], [8, 7, 5]),\n",
+ " ([9, 11], [1, 10, 2, 4, 3], [5, 7, 8]),\n",
+ " ([9, 11], [1, 10, 2, 4, 3], [5, 8, 7]),\n",
+ " ([9, 11], [1, 10, 2, 4, 3], [7, 5, 8]),\n",
+ " ([9, 11], [1, 10, 2, 4, 3], [7, 8, 5]),\n",
+ " ([9, 11], [1, 10, 2, 4, 3], [8, 5, 7]),\n",
+ " ([9, 11], [1, 10, 2, 4, 3], [8, 7, 5]),\n",
+ " ([9, 11], [1, 10, 2, 7], [3, 4, 5, 8]),\n",
+ " ([9, 11], [1, 10, 2, 7], [3, 4, 8, 5]),\n",
+ " ([9, 11], [1, 10, 2, 7], [3, 5, 4, 8]),\n",
+ " ([9, 11], [1, 10, 2, 7], [3, 5, 8, 4]),\n",
+ " ([9, 11], [1, 10, 2, 7], [3, 8, 4, 5]),\n",
+ " ([9, 11], [1, 10, 2, 7], [3, 8, 5, 4]),\n",
+ " ([9, 11], [1, 10, 2, 7], [4, 3, 5, 8]),\n",
+ " ([9, 11], [1, 10, 2, 7], [4, 3, 8, 5]),\n",
+ " ([9, 11], [1, 10, 2, 7], [4, 5, 3, 8]),\n",
+ " ([9, 11], [1, 10, 2, 7], [4, 5, 8, 3]),\n",
+ " ([9, 11], [1, 10, 2, 7], [4, 8, 3, 5]),\n",
+ " ([9, 11], [1, 10, 2, 7], [4, 8, 5, 3]),\n",
+ " ([9, 11], [1, 10, 2, 7], [5, 3, 4, 8]),\n",
+ " ([9, 11], [1, 10, 2, 7], [5, 3, 8, 4]),\n",
+ " ([9, 11], [1, 10, 2, 7], [5, 4, 3, 8]),\n",
+ " ([9, 11], [1, 10, 2, 7], [5, 4, 8, 3]),\n",
+ " ([9, 11], [1, 10, 2, 7], [5, 8, 3, 4]),\n",
+ " ([9, 11], [1, 10, 2, 7], [5, 8, 4, 3]),\n",
+ " ([9, 11], [1, 10, 2, 7], [8, 3, 4, 5]),\n",
+ " ([9, 11], [1, 10, 2, 7], [8, 3, 5, 4]),\n",
+ " ([9, 11], [1, 10, 2, 7], [8, 4, 3, 5]),\n",
+ " ([9, 11], [1, 10, 2, 7], [8, 4, 5, 3]),\n",
+ " ([9, 11], [1, 10, 2, 7], [8, 5, 3, 4]),\n",
+ " ([9, 11], [1, 10, 2, 7], [8, 5, 4, 3]),\n",
+ " ([9, 11], [1, 10, 3, 2, 4], [5, 7, 8]),\n",
+ " ([9, 11], [1, 10, 3, 2, 4], [5, 8, 7]),\n",
+ " ([9, 11], [1, 10, 3, 2, 4], [7, 5, 8]),\n",
+ " ([9, 11], [1, 10, 3, 2, 4], [7, 8, 5]),\n",
+ " ([9, 11], [1, 10, 3, 2, 4], [8, 5, 7]),\n",
+ " ([9, 11], [1, 10, 3, 2, 4], [8, 7, 5]),\n",
+ " ([9, 11], [1, 10, 3, 4, 2], [5, 7, 8]),\n",
+ " ([9, 11], [1, 10, 3, 4, 2], [5, 8, 7]),\n",
+ " ([9, 11], [1, 10, 3, 4, 2], [7, 5, 8]),\n",
+ " ([9, 11], [1, 10, 3, 4, 2], [7, 8, 5]),\n",
+ " ([9, 11], [1, 10, 3, 4, 2], [8, 5, 7]),\n",
+ " ([9, 11], [1, 10, 3, 4, 2], [8, 7, 5]),\n",
+ " ([9, 11], [1, 10, 4, 2, 3], [5, 7, 8]),\n",
+ " ([9, 11], [1, 10, 4, 2, 3], [5, 8, 7]),\n",
+ " ([9, 11], [1, 10, 4, 2, 3], [7, 5, 8]),\n",
+ " ([9, 11], [1, 10, 4, 2, 3], [7, 8, 5]),\n",
+ " ([9, 11], [1, 10, 4, 2, 3], [8, 5, 7]),\n",
+ " ([9, 11], [1, 10, 4, 2, 3], [8, 7, 5]),\n",
+ " ([9, 11], [1, 10, 4, 3, 2], [5, 7, 8]),\n",
+ " ([9, 11], [1, 10, 4, 3, 2], [5, 8, 7]),\n",
+ " ([9, 11], [1, 10, 4, 3, 2], [7, 5, 8]),\n",
+ " ([9, 11], [1, 10, 4, 3, 2], [7, 8, 5]),\n",
+ " ([9, 11], [1, 10, 4, 3, 2], [8, 5, 7]),\n",
+ " ([9, 11], [1, 10, 4, 3, 2], [8, 7, 5]),\n",
+ " ([9, 11], [1, 10, 4, 5], [2, 3, 7, 8]),\n",
+ " ([9, 11], [1, 10, 4, 5], [2, 3, 8, 7]),\n",
+ " ([9, 11], [1, 10, 4, 5], [2, 7, 3, 8]),\n",
+ " ([9, 11], [1, 10, 4, 5], [2, 7, 8, 3]),\n",
+ " ([9, 11], [1, 10, 4, 5], [2, 8, 3, 7]),\n",
+ " ([9, 11], [1, 10, 4, 5], [2, 8, 7, 3]),\n",
+ " ([9, 11], [1, 10, 4, 5], [3, 2, 7, 8]),\n",
+ " ([9, 11], [1, 10, 4, 5], [3, 2, 8, 7]),\n",
+ " ([9, 11], [1, 10, 4, 5], [3, 7, 2, 8]),\n",
+ " ([9, 11], [1, 10, 4, 5], [3, 7, 8, 2]),\n",
+ " ([9, 11], [1, 10, 4, 5], [3, 8, 2, 7]),\n",
+ " ([9, 11], [1, 10, 4, 5], [3, 8, 7, 2]),\n",
+ " ([9, 11], [1, 10, 4, 5], [7, 2, 3, 8]),\n",
+ " ([9, 11], [1, 10, 4, 5], [7, 2, 8, 3]),\n",
+ " ([9, 11], [1, 10, 4, 5], [7, 3, 2, 8]),\n",
+ " ([9, 11], [1, 10, 4, 5], [7, 3, 8, 2]),\n",
+ " ([9, 11], [1, 10, 4, 5], [7, 8, 2, 3]),\n",
+ " ([9, 11], [1, 10, 4, 5], [7, 8, 3, 2]),\n",
+ " ([9, 11], [1, 10, 4, 5], [8, 2, 3, 7]),\n",
+ " ([9, 11], [1, 10, 4, 5], [8, 2, 7, 3]),\n",
+ " ([9, 11], [1, 10, 4, 5], [8, 3, 2, 7]),\n",
+ " ([9, 11], [1, 10, 4, 5], [8, 3, 7, 2]),\n",
+ " ([9, 11], [1, 10, 4, 5], [8, 7, 2, 3]),\n",
+ " ([9, 11], [1, 10, 4, 5], [8, 7, 3, 2]),\n",
+ " ([9, 11], [1, 10, 5, 4], [2, 3, 7, 8]),\n",
+ " ([9, 11], [1, 10, 5, 4], [2, 3, 8, 7]),\n",
+ " ([9, 11], [1, 10, 5, 4], [2, 7, 3, 8]),\n",
+ " ([9, 11], [1, 10, 5, 4], [2, 7, 8, 3]),\n",
+ " ([9, 11], [1, 10, 5, 4], [2, 8, 3, 7]),\n",
+ " ([9, 11], [1, 10, 5, 4], [2, 8, 7, 3]),\n",
+ " ([9, 11], [1, 10, 5, 4], [3, 2, 7, 8]),\n",
+ " ([9, 11], [1, 10, 5, 4], [3, 2, 8, 7]),\n",
+ " ([9, 11], [1, 10, 5, 4], [3, 7, 2, 8]),\n",
+ " ([9, 11], [1, 10, 5, 4], [3, 7, 8, 2]),\n",
+ " ([9, 11], [1, 10, 5, 4], [3, 8, 2, 7]),\n",
+ " ([9, 11], [1, 10, 5, 4], [3, 8, 7, 2]),\n",
+ " ([9, 11], [1, 10, 5, 4], [7, 2, 3, 8]),\n",
+ " ([9, 11], [1, 10, 5, 4], [7, 2, 8, 3]),\n",
+ " ([9, 11], [1, 10, 5, 4], [7, 3, 2, 8]),\n",
+ " ([9, 11], [1, 10, 5, 4], [7, 3, 8, 2]),\n",
+ " ([9, 11], [1, 10, 5, 4], [7, 8, 2, 3]),\n",
+ " ([9, 11], [1, 10, 5, 4], [7, 8, 3, 2]),\n",
+ " ([9, 11], [1, 10, 5, 4], [8, 2, 3, 7]),\n",
+ " ([9, 11], [1, 10, 5, 4], [8, 2, 7, 3]),\n",
+ " ([9, 11], [1, 10, 5, 4], [8, 3, 2, 7]),\n",
+ " ([9, 11], [1, 10, 5, 4], [8, 3, 7, 2]),\n",
+ " ([9, 11], [1, 10, 5, 4], [8, 7, 2, 3]),\n",
+ " ([9, 11], [1, 10, 5, 4], [8, 7, 3, 2]),\n",
+ " ([9, 11], [1, 10, 7, 2], [3, 4, 5, 8]),\n",
+ " ([9, 11], [1, 10, 7, 2], [3, 4, 8, 5]),\n",
+ " ([9, 11], [1, 10, 7, 2], [3, 5, 4, 8]),\n",
+ " ([9, 11], [1, 10, 7, 2], [3, 5, 8, 4]),\n",
+ " ([9, 11], [1, 10, 7, 2], [3, 8, 4, 5]),\n",
+ " ([9, 11], [1, 10, 7, 2], [3, 8, 5, 4]),\n",
+ " ([9, 11], [1, 10, 7, 2], [4, 3, 5, 8]),\n",
+ " ([9, 11], [1, 10, 7, 2], [4, 3, 8, 5]),\n",
+ " ([9, 11], [1, 10, 7, 2], [4, 5, 3, 8]),\n",
+ " ([9, 11], [1, 10, 7, 2], [4, 5, 8, 3]),\n",
+ " ([9, 11], [1, 10, 7, 2], [4, 8, 3, 5]),\n",
+ " ([9, 11], [1, 10, 7, 2], [4, 8, 5, 3]),\n",
+ " ([9, 11], [1, 10, 7, 2], [5, 3, 4, 8]),\n",
+ " ([9, 11], [1, 10, 7, 2], [5, 3, 8, 4]),\n",
+ " ([9, 11], [1, 10, 7, 2], [5, 4, 3, 8]),\n",
+ " ([9, 11], [1, 10, 7, 2], [5, 4, 8, 3]),\n",
+ " ([9, 11], [1, 10, 7, 2], [5, 8, 3, 4]),\n",
+ " ([9, 11], [1, 10, 7, 2], [5, 8, 4, 3]),\n",
+ " ([9, 11], [1, 10, 7, 2], [8, 3, 4, 5]),\n",
+ " ([9, 11], [1, 10, 7, 2], [8, 3, 5, 4]),\n",
+ " ([9, 11], [1, 10, 7, 2], [8, 4, 3, 5]),\n",
+ " ([9, 11], [1, 10, 7, 2], [8, 4, 5, 3]),\n",
+ " ([9, 11], [1, 10, 7, 2], [8, 5, 3, 4]),\n",
+ " ([9, 11], [1, 10, 7, 2], [8, 5, 4, 3]),\n",
+ " ([9, 11], [2, 1, 3, 4, 10], [5, 7, 8]),\n",
+ " ([9, 11], [2, 1, 3, 4, 10], [5, 8, 7]),\n",
+ " ([9, 11], [2, 1, 3, 4, 10], [7, 5, 8]),\n",
+ " ([9, 11], [2, 1, 3, 4, 10], [7, 8, 5]),\n",
+ " ([9, 11], [2, 1, 3, 4, 10], [8, 5, 7]),\n",
+ " ([9, 11], [2, 1, 3, 4, 10], [8, 7, 5]),\n",
+ " ([9, 11], [2, 1, 3, 10, 4], [5, 7, 8]),\n",
+ " ([9, 11], [2, 1, 3, 10, 4], [5, 8, 7]),\n",
+ " ([9, 11], [2, 1, 3, 10, 4], [7, 5, 8]),\n",
+ " ([9, 11], [2, 1, 3, 10, 4], [7, 8, 5]),\n",
+ " ([9, 11], [2, 1, 3, 10, 4], [8, 5, 7]),\n",
+ " ([9, 11], [2, 1, 3, 10, 4], [8, 7, 5]),\n",
+ " ([9, 11], [2, 1, 4, 3, 10], [5, 7, 8]),\n",
+ " ([9, 11], [2, 1, 4, 3, 10], [5, 8, 7]),\n",
+ " ([9, 11], [2, 1, 4, 3, 10], [7, 5, 8]),\n",
+ " ([9, 11], [2, 1, 4, 3, 10], [7, 8, 5]),\n",
+ " ([9, 11], [2, 1, 4, 3, 10], [8, 5, 7]),\n",
+ " ([9, 11], [2, 1, 4, 3, 10], [8, 7, 5]),\n",
+ " ([9, 11], [2, 1, 4, 5, 8], [3, 7, 10]),\n",
+ " ([9, 11], [2, 1, 4, 5, 8], [3, 10, 7]),\n",
+ " ([9, 11], [2, 1, 4, 5, 8], [7, 3, 10]),\n",
+ " ([9, 11], [2, 1, 4, 5, 8], [7, 10, 3]),\n",
+ " ([9, 11], [2, 1, 4, 5, 8], [10, 3, 7]),\n",
+ " ([9, 11], [2, 1, 4, 5, 8], [10, 7, 3]),\n",
+ " ([9, 11], [2, 1, 4, 8, 5], [3, 7, 10]),\n",
+ " ([9, 11], [2, 1, 4, 8, 5], [3, 10, 7]),\n",
+ " ([9, 11], [2, 1, 4, 8, 5], [7, 3, 10]),\n",
+ " ([9, 11], [2, 1, 4, 8, 5], [7, 10, 3]),\n",
+ " ([9, 11], [2, 1, 4, 8, 5], [10, 3, 7]),\n",
+ " ([9, 11], [2, 1, 4, 8, 5], [10, 7, 3]),\n",
+ " ([9, 11], [2, 1, 4, 10, 3], [5, 7, 8]),\n",
+ " ([9, 11], [2, 1, 4, 10, 3], [5, 8, 7]),\n",
+ " ([9, 11], [2, 1, 4, 10, 3], [7, 5, 8]),\n",
+ " ([9, 11], [2, 1, 4, 10, 3], [7, 8, 5]),\n",
+ " ([9, 11], [2, 1, 4, 10, 3], [8, 5, 7]),\n",
+ " ([9, 11], [2, 1, 4, 10, 3], [8, 7, 5]),\n",
+ " ([9, 11], [2, 1, 5, 4, 8], [3, 7, 10]),\n",
+ " ([9, 11], [2, 1, 5, 4, 8], [3, 10, 7]),\n",
+ " ([9, 11], [2, 1, 5, 4, 8], [7, 3, 10]),\n",
+ " ([9, 11], [2, 1, 5, 4, 8], [7, 10, 3]),\n",
+ " ([9, 11], [2, 1, 5, 4, 8], [10, 3, 7]),\n",
+ " ([9, 11], [2, 1, 5, 4, 8], [10, 7, 3]),\n",
+ " ([9, 11], [2, 1, 5, 8, 4], [3, 7, 10]),\n",
+ " ([9, 11], [2, 1, 5, 8, 4], [3, 10, 7]),\n",
+ " ([9, 11], [2, 1, 5, 8, 4], [7, 3, 10]),\n",
+ " ([9, 11], [2, 1, 5, 8, 4], [7, 10, 3]),\n",
+ " ([9, 11], [2, 1, 5, 8, 4], [10, 3, 7]),\n",
+ " ([9, 11], [2, 1, 5, 8, 4], [10, 7, 3]),\n",
+ " ([9, 11], [2, 1, 7, 10], [3, 4, 5, 8]),\n",
+ " ([9, 11], [2, 1, 7, 10], [3, 4, 8, 5]),\n",
+ " ([9, 11], [2, 1, 7, 10], [3, 5, 4, 8]),\n",
+ " ([9, 11], [2, 1, 7, 10], [3, 5, 8, 4]),\n",
+ " ([9, 11], [2, 1, 7, 10], [3, 8, 4, 5]),\n",
+ " ([9, 11], [2, 1, 7, 10], [3, 8, 5, 4]),\n",
+ " ([9, 11], [2, 1, 7, 10], [4, 3, 5, 8]),\n",
+ " ([9, 11], [2, 1, 7, 10], [4, 3, 8, 5]),\n",
+ " ([9, 11], [2, 1, 7, 10], [4, 5, 3, 8]),\n",
+ " ([9, 11], [2, 1, 7, 10], [4, 5, 8, 3]),\n",
+ " ([9, 11], [2, 1, 7, 10], [4, 8, 3, 5]),\n",
+ " ([9, 11], [2, 1, 7, 10], [4, 8, 5, 3]),\n",
+ " ([9, 11], [2, 1, 7, 10], [5, 3, 4, 8]),\n",
+ " ([9, 11], [2, 1, 7, 10], [5, 3, 8, 4]),\n",
+ " ([9, 11], [2, 1, 7, 10], [5, 4, 3, 8]),\n",
+ " ([9, 11], [2, 1, 7, 10], [5, 4, 8, 3]),\n",
+ " ([9, 11], [2, 1, 7, 10], [5, 8, 3, 4]),\n",
+ " ([9, 11], [2, 1, 7, 10], [5, 8, 4, 3]),\n",
+ " ([9, 11], [2, 1, 7, 10], [8, 3, 4, 5]),\n",
+ " ([9, 11], [2, 1, 7, 10], [8, 3, 5, 4]),\n",
+ " ([9, 11], [2, 1, 7, 10], [8, 4, 3, 5]),\n",
+ " ([9, 11], [2, 1, 7, 10], [8, 4, 5, 3]),\n",
+ " ([9, 11], [2, 1, 7, 10], [8, 5, 3, 4]),\n",
+ " ([9, 11], [2, 1, 7, 10], [8, 5, 4, 3]),\n",
+ " ([9, 11], [2, 1, 8, 4, 5], [3, 7, 10]),\n",
+ " ([9, 11], [2, 1, 8, 4, 5], [3, 10, 7]),\n",
+ " ([9, 11], [2, 1, 8, 4, 5], [7, 3, 10]),\n",
+ " ([9, 11], [2, 1, 8, 4, 5], [7, 10, 3]),\n",
+ " ([9, 11], [2, 1, 8, 4, 5], [10, 3, 7]),\n",
+ " ([9, 11], [2, 1, 8, 4, 5], [10, 7, 3]),\n",
+ " ([9, 11], [2, 1, 8, 5, 4], [3, 7, 10]),\n",
+ " ([9, 11], [2, 1, 8, 5, 4], [3, 10, 7]),\n",
+ " ([9, 11], [2, 1, 8, 5, 4], [7, 3, 10]),\n",
+ " ([9, 11], [2, 1, 8, 5, 4], [7, 10, 3]),\n",
+ " ([9, 11], [2, 1, 8, 5, 4], [10, 3, 7]),\n",
+ " ([9, 11], [2, 1, 8, 5, 4], [10, 7, 3]),\n",
+ " ([9, 11], [2, 1, 10, 3, 4], [5, 7, 8]),\n",
+ " ([9, 11], [2, 1, 10, 3, 4], [5, 8, 7]),\n",
+ " ([9, 11], [2, 1, 10, 3, 4], [7, 5, 8]),\n",
+ " ([9, 11], [2, 1, 10, 3, 4], [7, 8, 5]),\n",
+ " ([9, 11], [2, 1, 10, 3, 4], [8, 5, 7]),\n",
+ " ([9, 11], [2, 1, 10, 3, 4], [8, 7, 5]),\n",
+ " ([9, 11], [2, 1, 10, 4, 3], [5, 7, 8]),\n",
+ " ([9, 11], [2, 1, 10, 4, 3], [5, 8, 7]),\n",
+ " ([9, 11], [2, 1, 10, 4, 3], [7, 5, 8]),\n",
+ " ([9, 11], [2, 1, 10, 4, 3], [7, 8, 5]),\n",
+ " ([9, 11], [2, 1, 10, 4, 3], [8, 5, 7]),\n",
+ " ([9, 11], [2, 1, 10, 4, 3], [8, 7, 5]),\n",
+ " ([9, 11], [2, 1, 10, 7], [3, 4, 5, 8]),\n",
+ " ([9, 11], [2, 1, 10, 7], [3, 4, 8, 5]),\n",
+ " ([9, 11], [2, 1, 10, 7], [3, 5, 4, 8]),\n",
+ " ([9, 11], [2, 1, 10, 7], [3, 5, 8, 4]),\n",
+ " ([9, 11], [2, 1, 10, 7], [3, 8, 4, 5]),\n",
+ " ([9, 11], [2, 1, 10, 7], [3, 8, 5, 4]),\n",
+ " ([9, 11], [2, 1, 10, 7], [4, 3, 5, 8]),\n",
+ " ([9, 11], [2, 1, 10, 7], [4, 3, 8, 5]),\n",
+ " ([9, 11], [2, 1, 10, 7], [4, 5, 3, 8]),\n",
+ " ([9, 11], [2, 1, 10, 7], [4, 5, 8, 3]),\n",
+ " ([9, 11], [2, 1, 10, 7], [4, 8, 3, 5]),\n",
+ " ([9, 11], [2, 1, 10, 7], [4, 8, 5, 3]),\n",
+ " ([9, 11], [2, 1, 10, 7], [5, 3, 4, 8]),\n",
+ " ([9, 11], [2, 1, 10, 7], [5, 3, 8, 4]),\n",
+ " ([9, 11], [2, 1, 10, 7], [5, 4, 3, 8]),\n",
+ " ([9, 11], [2, 1, 10, 7], [5, 4, 8, 3]),\n",
+ " ([9, 11], [2, 1, 10, 7], [5, 8, 3, 4]),\n",
+ " ([9, 11], [2, 1, 10, 7], [5, 8, 4, 3]),\n",
+ " ([9, 11], [2, 1, 10, 7], [8, 3, 4, 5]),\n",
+ " ([9, 11], [2, 1, 10, 7], [8, 3, 5, 4]),\n",
+ " ([9, 11], [2, 1, 10, 7], [8, 4, 3, 5]),\n",
+ " ([9, 11], [2, 1, 10, 7], [8, 4, 5, 3]),\n",
+ " ([9, 11], [2, 1, 10, 7], [8, 5, 3, 4]),\n",
+ " ([9, 11], [2, 1, 10, 7], [8, 5, 4, 3]),\n",
+ " ([9, 11], [2, 3, 1, 4, 10], [5, 7, 8]),\n",
+ " ([9, 11], [2, 3, 1, 4, 10], [5, 8, 7]),\n",
+ " ([9, 11], [2, 3, 1, 4, 10], [7, 5, 8]),\n",
+ " ([9, 11], [2, 3, 1, 4, 10], [7, 8, 5]),\n",
+ " ([9, 11], [2, 3, 1, 4, 10], [8, 5, 7]),\n",
+ " ([9, 11], [2, 3, 1, 4, 10], [8, 7, 5]),\n",
+ " ([9, 11], [2, 3, 1, 10, 4], [5, 7, 8]),\n",
+ " ([9, 11], [2, 3, 1, 10, 4], [5, 8, 7]),\n",
+ " ([9, 11], [2, 3, 1, 10, 4], [7, 5, 8]),\n",
+ " ([9, 11], [2, 3, 1, 10, 4], [7, 8, 5]),\n",
+ " ([9, 11], [2, 3, 1, 10, 4], [8, 5, 7]),\n",
+ " ([9, 11], [2, 3, 1, 10, 4], [8, 7, 5]),\n",
+ " ([9, 11], [2, 3, 4, 1, 10], [5, 7, 8]),\n",
+ " ([9, 11], [2, 3, 4, 1, 10], [5, 8, 7]),\n",
+ " ([9, 11], [2, 3, 4, 1, 10], [7, 5, 8]),\n",
+ " ([9, 11], [2, 3, 4, 1, 10], [7, 8, 5]),\n",
+ " ...]"
+ ]
+ },
+ "execution_count": 18,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#valids = []\n",
+ "#for p in itertools.permutations(presents):\n",
+ "# totals = itertools.accumulate(p)\n",
+ "# pairs = zip(p, totals)\n",
+ "# g1, g2, g3 = split(pairs)\n",
+ "# if valid(g1, g2, g3):\n",
+ "# valids += [(g1, g2, g3)]\n",
+ "#valids"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "def subsets_with_sum(items, dsum):\n",
+ " subsets = set()\n",
+ " for i in range(len(items)):\n",
+ " subsets |= set(frozenset(s) for s in itertools.combinations(items, i)\n",
+ " if sum(s) == dsum)\n",
+ " return subsets"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[(1, 2, 17), (2, 5, 13)]"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "list(filter(lambda s: sum(s) == 20, (s for s in itertools.combinations(presents, 3))))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "429102"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "subsets = subsets_with_sum(presents, group_weight)\n",
+ "len(subsets)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "6"
+ ]
+ },
+ "execution_count": 23,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "min(len(s) for s in subsets)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "True"
+ ]
+ },
+ "execution_count": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "g1_size = min(len(s) for s in subsets)\n",
+ "g1_candidates = [s for s in subsets if len(s) == 6]\n",
+ "g23_candidates = [s for s in subsets if len(s) > 6]\n",
+ "len(subsets) == (len(g1_candidates) + len(g23_candidates))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "248"
+ ]
+ },
+ "execution_count": 25,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "len(g1_candidates)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[(frozenset({43, 79, 89, 97, 101, 103}),\n",
+ " (frozenset({2, 7, 23, 43, 61, 71, 89, 107, 109}),\n",
+ " frozenset({2, 7, 23, 53, 61, 71, 79, 107, 109}))),\n",
+ " (frozenset({43, 79, 89, 97, 101, 103}),\n",
+ " (frozenset({2, 7, 23, 43, 61, 71, 89, 107, 109}),\n",
+ " frozenset({1, 5, 13, 19, 29, 31, 43, 59, 67, 73, 83, 89}))),\n",
+ " (frozenset({43, 79, 89, 97, 101, 103}),\n",
+ " (frozenset({2, 7, 23, 53, 61, 71, 79, 107, 109}),\n",
+ " frozenset({1, 5, 13, 19, 29, 31, 43, 59, 67, 73, 83, 89}))),\n",
+ " (frozenset({67, 73, 79, 89, 101, 103}),\n",
+ " (frozenset({2, 7, 23, 43, 61, 71, 89, 107, 109}),\n",
+ " frozenset({2, 7, 23, 53, 61, 71, 79, 107, 109}))),\n",
+ " (frozenset({67, 73, 79, 89, 101, 103}),\n",
+ " (frozenset({2, 7, 23, 43, 61, 71, 89, 107, 109}),\n",
+ " frozenset({1, 5, 13, 19, 29, 31, 43, 59, 67, 73, 83, 89}))),\n",
+ " (frozenset({67, 73, 79, 89, 101, 103}),\n",
+ " (frozenset({2, 7, 23, 53, 61, 71, 79, 107, 109}),\n",
+ " frozenset({1, 5, 13, 19, 29, 31, 43, 59, 67, 73, 83, 89})))]"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "list(itertools.product(g1_candidates[:2], \n",
+ " itertools.combinations(g23_candidates[:3], 2)))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "def solutions(g1s, g23s):\n",
+ " solutions = []\n",
+ " for g1 in g1s:\n",
+ " vg23s = [g for g in g23s if not g1 & g]\n",
+ " if any(g23 for g23 in itertools.combinations(vg23s, 2)\n",
+ " if not g23[0] & g23[1]):\n",
+ " solutions += [g1]\n",
+ " return solutions"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "23901"
+ ]
+ },
+ "execution_count": 30,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "vg23s = [g for g in g23_candidates if not g1_candidates[0] & g]\n",
+ "len(vg23s)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[frozenset({43, 79, 89, 97, 101, 103}),\n",
+ " frozenset({67, 73, 79, 89, 101, 103}),\n",
+ " frozenset({17, 73, 97, 103, 109, 113}),\n",
+ " frozenset({43, 67, 83, 103, 107, 109}),\n",
+ " frozenset({19, 71, 97, 103, 109, 113}),\n",
+ " frozenset({19, 61, 103, 107, 109, 113}),\n",
+ " frozenset({59, 61, 73, 97, 109, 113}),\n",
+ " frozenset({53, 59, 83, 97, 107, 113}),\n",
+ " frozenset({23, 83, 89, 97, 107, 113}),\n",
+ " frozenset({53, 73, 83, 89, 101, 113}),\n",
+ " frozenset({41, 59, 89, 103, 107, 113}),\n",
+ " frozenset({41, 53, 89, 107, 109, 113}),\n",
+ " frozenset({41, 61, 97, 101, 103, 109}),\n",
+ " frozenset({61, 73, 79, 89, 97, 113}),\n",
+ " frozenset({13, 89, 97, 101, 103, 109}),\n",
+ " frozenset({53, 67, 73, 97, 109, 113}),\n",
+ " frozenset({19, 73, 97, 103, 107, 113}),\n",
+ " frozenset({43, 73, 83, 97, 107, 109}),\n",
+ " frozenset({5, 83, 101, 103, 107, 113}),\n",
+ " frozenset({61, 79, 83, 89, 97, 103}),\n",
+ " frozenset({43, 59, 89, 101, 107, 113}),\n",
+ " frozenset({53, 59, 79, 101, 107, 113}),\n",
+ " frozenset({23, 73, 97, 103, 107, 109}),\n",
+ " frozenset({37, 61, 89, 103, 109, 113}),\n",
+ " frozenset({37, 53, 97, 103, 109, 113}),\n",
+ " frozenset({41, 79, 83, 97, 103, 109}),\n",
+ " frozenset({53, 61, 89, 97, 103, 109}),\n",
+ " frozenset({67, 71, 73, 97, 101, 103}),\n",
+ " frozenset({43, 73, 83, 97, 103, 113}),\n",
+ " frozenset({41, 61, 89, 101, 107, 113}),\n",
+ " frozenset({59, 61, 71, 101, 107, 113}),\n",
+ " frozenset({13, 73, 97, 107, 109, 113}),\n",
+ " frozenset({37, 73, 89, 97, 107, 109}),\n",
+ " frozenset({5, 89, 97, 101, 107, 113}),\n",
+ " frozenset({43, 73, 79, 97, 107, 113}),\n",
+ " frozenset({29, 79, 83, 101, 107, 113}),\n",
+ " frozenset({43, 67, 89, 101, 103, 109}),\n",
+ " frozenset({53, 67, 79, 101, 103, 109}),\n",
+ " frozenset({29, 73, 89, 101, 107, 113}),\n",
+ " frozenset({53, 59, 89, 101, 103, 107}),\n",
+ " frozenset({43, 73, 83, 101, 103, 109}),\n",
+ " frozenset({59, 71, 73, 89, 107, 113}),\n",
+ " frozenset({43, 61, 89, 103, 107, 109}),\n",
+ " frozenset({53, 61, 79, 103, 107, 109}),\n",
+ " frozenset({61, 71, 83, 89, 101, 107}),\n",
+ " frozenset({59, 73, 79, 89, 103, 109}),\n",
+ " frozenset({29, 83, 89, 101, 103, 107}),\n",
+ " frozenset({41, 73, 79, 103, 107, 109}),\n",
+ " frozenset({67, 73, 79, 83, 103, 107}),\n",
+ " frozenset({61, 67, 71, 101, 103, 109}),\n",
+ " frozenset({61, 71, 73, 97, 103, 107}),\n",
+ " frozenset({71, 73, 79, 89, 97, 103}),\n",
+ " frozenset({53, 59, 83, 101, 107, 109}),\n",
+ " frozenset({23, 79, 97, 101, 103, 109}),\n",
+ " frozenset({61, 67, 79, 89, 103, 113}),\n",
+ " frozenset({59, 71, 83, 89, 97, 113}),\n",
+ " frozenset({59, 61, 79, 97, 103, 113}),\n",
+ " frozenset({43, 67, 73, 107, 109, 113}),\n",
+ " frozenset({59, 71, 79, 89, 101, 113}),\n",
+ " frozenset({53, 71, 79, 89, 107, 113}),\n",
+ " frozenset({61, 71, 73, 97, 101, 109}),\n",
+ " frozenset({43, 71, 79, 97, 109, 113}),\n",
+ " frozenset({43, 71, 79, 103, 107, 109}),\n",
+ " frozenset({37, 67, 89, 97, 109, 113}),\n",
+ " frozenset({59, 71, 79, 83, 107, 113}),\n",
+ " frozenset({43, 73, 79, 101, 107, 109}),\n",
+ " frozenset({31, 61, 101, 103, 107, 109}),\n",
+ " frozenset({31, 73, 83, 103, 109, 113}),\n",
+ " frozenset({59, 67, 73, 97, 107, 109}),\n",
+ " frozenset({61, 73, 79, 83, 103, 113}),\n",
+ " frozenset({23, 59, 101, 107, 109, 113}),\n",
+ " frozenset({37, 73, 79, 103, 107, 113}),\n",
+ " frozenset({53, 59, 83, 101, 103, 113}),\n",
+ " frozenset({43, 53, 97, 103, 107, 109}),\n",
+ " frozenset({53, 71, 83, 89, 103, 113}),\n",
+ " frozenset({43, 71, 73, 103, 109, 113}),\n",
+ " frozenset({43, 79, 83, 97, 101, 109}),\n",
+ " frozenset({17, 71, 101, 103, 107, 113}),\n",
+ " frozenset({61, 73, 79, 89, 103, 107}),\n",
+ " frozenset({53, 59, 89, 97, 101, 113}),\n",
+ " frozenset({31, 79, 89, 97, 107, 109}),\n",
+ " frozenset({1, 89, 97, 103, 109, 113}),\n",
+ " frozenset({59, 71, 73, 97, 103, 109}),\n",
+ " frozenset({31, 83, 89, 97, 103, 109}),\n",
+ " frozenset({13, 79, 97, 101, 109, 113}),\n",
+ " frozenset({37, 79, 89, 97, 101, 109}),\n",
+ " frozenset({59, 71, 83, 89, 103, 107}),\n",
+ " frozenset({41, 67, 79, 103, 109, 113}),\n",
+ " frozenset({19, 73, 101, 103, 107, 109}),\n",
+ " frozenset({59, 61, 79, 101, 103, 109}),\n",
+ " frozenset({41, 67, 83, 101, 107, 113}),\n",
+ " frozenset({37, 67, 79, 107, 109, 113}),\n",
+ " frozenset({29, 59, 101, 103, 107, 113}),\n",
+ " frozenset({17, 83, 89, 101, 109, 113}),\n",
+ " frozenset({41, 73, 89, 97, 103, 109}),\n",
+ " frozenset({67, 71, 79, 83, 103, 109}),\n",
+ " frozenset({53, 71, 83, 97, 101, 107}),\n",
+ " frozenset({13, 73, 101, 103, 109, 113}),\n",
+ " frozenset({37, 73, 89, 101, 103, 109}),\n",
+ " frozenset({31, 73, 89, 97, 109, 113}),\n",
+ " frozenset({31, 67, 97, 101, 103, 113}),\n",
+ " frozenset({19, 67, 97, 107, 109, 113}),\n",
+ " frozenset({7, 89, 97, 103, 107, 109}),\n",
+ " frozenset({19, 79, 97, 101, 107, 109}),\n",
+ " frozenset({67, 73, 79, 83, 97, 113}),\n",
+ " frozenset({43, 61, 83, 103, 109, 113}),\n",
+ " frozenset({37, 71, 79, 103, 109, 113}),\n",
+ " frozenset({23, 71, 89, 107, 109, 113}),\n",
+ " frozenset({23, 83, 89, 101, 103, 113}),\n",
+ " frozenset({31, 79, 83, 97, 109, 113}),\n",
+ " frozenset({31, 61, 97, 101, 109, 113}),\n",
+ " frozenset({29, 71, 89, 101, 109, 113}),\n",
+ " frozenset({43, 67, 79, 103, 107, 113}),\n",
+ " frozenset({1, 79, 103, 107, 109, 113}),\n",
+ " frozenset({29, 61, 97, 103, 109, 113}),\n",
+ " frozenset({7, 73, 103, 107, 109, 113}),\n",
+ " frozenset({61, 73, 79, 83, 107, 109}),\n",
+ " frozenset({53, 67, 73, 103, 107, 109}),\n",
+ " frozenset({41, 71, 79, 101, 107, 113}),\n",
+ " frozenset({61, 67, 71, 97, 103, 113}),\n",
+ " frozenset({43, 73, 79, 101, 103, 113}),\n",
+ " frozenset({43, 73, 89, 97, 101, 109}),\n",
+ " frozenset({53, 73, 79, 97, 101, 109}),\n",
+ " frozenset({43, 67, 83, 97, 109, 113}),\n",
+ " frozenset({13, 83, 97, 103, 107, 109}),\n",
+ " frozenset({31, 73, 89, 103, 107, 109}),\n",
+ " frozenset({61, 67, 83, 89, 103, 109}),\n",
+ " frozenset({59, 71, 83, 89, 101, 109}),\n",
+ " frozenset({53, 71, 83, 89, 107, 109}),\n",
+ " frozenset({3, 79, 101, 107, 109, 113}),\n",
+ " frozenset({61, 71, 79, 97, 101, 103}),\n",
+ " frozenset({59, 73, 79, 97, 101, 103}),\n",
+ " frozenset({7, 79, 97, 107, 109, 113}),\n",
+ " frozenset({61, 67, 79, 89, 107, 109}),\n",
+ " frozenset({43, 67, 89, 97, 107, 109}),\n",
+ " frozenset({53, 67, 79, 97, 107, 109}),\n",
+ " frozenset({61, 67, 73, 97, 101, 113}),\n",
+ " frozenset({37, 73, 83, 103, 107, 109}),\n",
+ " frozenset({43, 73, 89, 97, 103, 107}),\n",
+ " frozenset({53, 73, 79, 97, 103, 107}),\n",
+ " frozenset({37, 73, 83, 97, 109, 113}),\n",
+ " frozenset({37, 67, 97, 101, 103, 107}),\n",
+ " frozenset({13, 79, 97, 103, 107, 113}),\n",
+ " frozenset({37, 79, 89, 97, 103, 107}),\n",
+ " frozenset({31, 67, 89, 103, 109, 113}),\n",
+ " frozenset({53, 67, 83, 97, 103, 109}),\n",
+ " frozenset({41, 71, 89, 97, 101, 113}),\n",
+ " frozenset({67, 71, 73, 79, 109, 113}),\n",
+ " frozenset({37, 79, 83, 97, 107, 109}),\n",
+ " frozenset({13, 67, 103, 107, 109, 113}),\n",
+ " frozenset({37, 67, 89, 103, 107, 109}),\n",
+ " frozenset({3, 83, 97, 107, 109, 113}),\n",
+ " frozenset({67, 73, 79, 83, 101, 109}),\n",
+ " frozenset({41, 73, 79, 97, 109, 113}),\n",
+ " frozenset({37, 71, 83, 101, 107, 113}),\n",
+ " frozenset({59, 61, 67, 103, 109, 113}),\n",
+ " frozenset({37, 79, 83, 97, 103, 113}),\n",
+ " frozenset({41, 79, 83, 89, 107, 113}),\n",
+ " frozenset({41, 53, 97, 101, 107, 113}),\n",
+ " frozenset({37, 73, 89, 97, 103, 113}),\n",
+ " frozenset({23, 67, 97, 103, 109, 113}),\n",
+ " frozenset({23, 71, 97, 101, 107, 113}),\n",
+ " frozenset({3, 89, 97, 103, 107, 113}),\n",
+ " frozenset({19, 79, 89, 103, 109, 113}),\n",
+ " frozenset({37, 59, 97, 103, 107, 109}),\n",
+ " frozenset({19, 83, 97, 101, 103, 109}),\n",
+ " frozenset({61, 67, 73, 89, 109, 113}),\n",
+ " frozenset({7, 79, 101, 103, 109, 113}),\n",
+ " frozenset({17, 79, 97, 103, 107, 109}),\n",
+ " frozenset({41, 71, 89, 101, 103, 107}),\n",
+ " frozenset({31, 79, 89, 101, 103, 109}),\n",
+ " frozenset({29, 53, 101, 107, 109, 113}),\n",
+ " frozenset({61, 73, 83, 89, 97, 109}),\n",
+ " frozenset({43, 67, 89, 97, 103, 113}),\n",
+ " frozenset({53, 67, 79, 97, 103, 113}),\n",
+ " frozenset({43, 71, 89, 97, 103, 109}),\n",
+ " frozenset({53, 71, 79, 97, 103, 109}),\n",
+ " frozenset({53, 59, 71, 107, 109, 113}),\n",
+ " frozenset({67, 71, 79, 89, 97, 109}),\n",
+ " frozenset({53, 67, 83, 89, 107, 113}),\n",
+ " frozenset({59, 67, 83, 89, 101, 113}),\n",
+ " frozenset({31, 59, 97, 103, 109, 113}),\n",
+ " frozenset({59, 73, 83, 89, 101, 107}),\n",
+ " frozenset({59, 61, 83, 97, 103, 109}),\n",
+ " frozenset({41, 71, 83, 101, 107, 109}),\n",
+ " frozenset({3, 89, 97, 101, 109, 113}),\n",
+ " frozenset({31, 73, 79, 107, 109, 113}),\n",
+ " frozenset({61, 67, 79, 83, 109, 113}),\n",
+ " frozenset({17, 83, 89, 103, 107, 113}),\n",
+ " frozenset({71, 73, 79, 83, 97, 109}),\n",
+ " frozenset({43, 59, 97, 101, 103, 109}),\n",
+ " frozenset({41, 71, 83, 101, 103, 113}),\n",
+ " frozenset({59, 61, 83, 89, 107, 113}),\n",
+ " frozenset({53, 67, 71, 101, 107, 113}),\n",
+ " frozenset({61, 67, 71, 97, 107, 109}),\n",
+ " frozenset({59, 67, 79, 97, 103, 107}),\n",
+ " frozenset({3, 83, 101, 103, 109, 113}),\n",
+ " frozenset({23, 79, 89, 101, 107, 113}),\n",
+ " frozenset({31, 79, 83, 103, 107, 109}),\n",
+ " frozenset({61, 67, 83, 97, 101, 103}),\n",
+ " frozenset({53, 61, 73, 103, 109, 113}),\n",
+ " frozenset({7, 83, 97, 103, 109, 113}),\n",
+ " frozenset({13, 79, 101, 103, 107, 109}),\n",
+ " frozenset({29, 83, 89, 97, 101, 113}),\n",
+ " frozenset({31, 71, 89, 101, 107, 113}),\n",
+ " frozenset({19, 79, 97, 101, 103, 113}),\n",
+ " frozenset({61, 67, 73, 101, 103, 107}),\n",
+ " frozenset({31, 67, 97, 101, 107, 109}),\n",
+ " frozenset({41, 71, 83, 97, 107, 113}),\n",
+ " frozenset({19, 67, 101, 103, 109, 113}),\n",
+ " frozenset({43, 61, 89, 97, 109, 113}),\n",
+ " frozenset({53, 61, 79, 97, 109, 113}),\n",
+ " frozenset({37, 61, 97, 101, 107, 109}),\n",
+ " frozenset({31, 73, 97, 101, 103, 107}),\n",
+ " frozenset({29, 73, 97, 101, 103, 109}),\n",
+ " frozenset({31, 61, 97, 103, 107, 113}),\n",
+ " frozenset({61, 67, 79, 97, 101, 107}),\n",
+ " frozenset({61, 73, 79, 89, 101, 109}),\n",
+ " frozenset({67, 71, 73, 89, 103, 109}),\n",
+ " frozenset({41, 59, 89, 101, 109, 113}),\n",
+ " frozenset({59, 67, 73, 101, 103, 109}),\n",
+ " frozenset({43, 67, 79, 101, 109, 113}),\n",
+ " frozenset({67, 73, 79, 89, 97, 107}),\n",
+ " frozenset({43, 79, 83, 97, 103, 107}),\n",
+ " frozenset({59, 61, 73, 103, 107, 109}),\n",
+ " frozenset({43, 61, 97, 101, 103, 107}),\n",
+ " frozenset({61, 71, 79, 89, 103, 109}),\n",
+ " frozenset({59, 67, 73, 97, 103, 113}),\n",
+ " frozenset({43, 61, 79, 107, 109, 113}),\n",
+ " frozenset({59, 67, 79, 97, 101, 109}),\n",
+ " frozenset({29, 71, 89, 103, 107, 113}),\n",
+ " frozenset({31, 79, 89, 97, 103, 113}),\n",
+ " frozenset({3, 89, 101, 103, 107, 109}),\n",
+ " frozenset({19, 83, 89, 101, 107, 113}),\n",
+ " frozenset({19, 73, 97, 101, 109, 113}),\n",
+ " frozenset({37, 43, 103, 107, 109, 113}),\n",
+ " frozenset({29, 71, 83, 107, 109, 113}),\n",
+ " frozenset({37, 73, 79, 101, 109, 113}),\n",
+ " frozenset({59, 61, 79, 97, 107, 109}),\n",
+ " frozenset({53, 79, 83, 89, 101, 107}),\n",
+ " frozenset({41, 59, 83, 107, 109, 113}),\n",
+ " frozenset({31, 71, 97, 101, 103, 109}),\n",
+ " frozenset({37, 67, 83, 103, 109, 113}),\n",
+ " frozenset({67, 73, 83, 89, 97, 103}),\n",
+ " frozenset({37, 79, 83, 101, 103, 109}),\n",
+ " frozenset({29, 67, 97, 103, 107, 109}),\n",
+ " frozenset({37, 61, 97, 101, 103, 113}),\n",
+ " frozenset({23, 83, 89, 101, 107, 109})]"
+ ]
+ },
+ "execution_count": 34,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "valid_g1s = solutions(g1_candidates, g23_candidates)\n",
+ "valid_g1s"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "10723906903"
+ ]
+ },
+ "execution_count": 35,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "best_qe = min(prod(s) for s in valid_g1s) \n",
+ "best_qe"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#Part 2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "384"
+ ]
+ },
+ "execution_count": 18,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "group_weight2 = sum(presents) // 4\n",
+ "group_weight2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "108230"
+ ]
+ },
+ "execution_count": 20,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "subsets2 = subsets_with_sum(presents, group_weight2)\n",
+ "len(subsets2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(4, 18)"
+ ]
+ },
+ "execution_count": 37,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "g1_size = min(len(s) for s in subsets2)\n",
+ "g1_candidates = [s for s in subsets2 if len(s) == g1_size]\n",
+ "g234_candidates = [s for s in subsets2 if len(s) > g1_size]\n",
+ "g1_size, len(g1_candidates)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "def solutions2(g1s, g234s):\n",
+ " solutions = []\n",
+ " for g1 in g1s:\n",
+ " vg234s = [g for g in g234s if not g1 & g]\n",
+ " if any(g234 for g234 in itertools.combinations(vg234s, 3)\n",
+ " if not g234[0] & g234[1]\n",
+ " if not g234[0] & g234[2]\n",
+ " if not g234[1] & g234[2]):\n",
+ " solutions += [g1]\n",
+ " return solutions"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[frozenset({79, 83, 109, 113}),\n",
+ " frozenset({67, 101, 107, 109}),\n",
+ " frozenset({79, 97, 101, 107}),\n",
+ " frozenset({71, 101, 103, 109}),\n",
+ " frozenset({71, 97, 107, 109}),\n",
+ " frozenset({83, 89, 103, 109}),\n",
+ " frozenset({61, 103, 107, 113}),\n",
+ " frozenset({73, 89, 109, 113}),\n",
+ " frozenset({83, 97, 101, 103}),\n",
+ " frozenset({73, 97, 101, 113}),\n",
+ " frozenset({67, 97, 107, 113}),\n",
+ " frozenset({71, 97, 103, 113}),\n",
+ " frozenset({67, 101, 103, 113}),\n",
+ " frozenset({73, 101, 103, 107}),\n",
+ " frozenset({59, 103, 109, 113}),\n",
+ " frozenset({79, 89, 103, 113}),\n",
+ " frozenset({61, 101, 109, 113}),\n",
+ " frozenset({79, 89, 107, 109})]"
+ ]
+ },
+ "execution_count": 39,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "valid_g1s = solutions2(g1_candidates, g234_candidates)\n",
+ "valid_g1s"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "74850409"
+ ]
+ },
+ "execution_count": 40,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "best_qe = min(prod(s) for s in valid_g1s) \n",
+ "best_qe"
+ ]
+ },
+ {
+ "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.4.3"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}